SEN2022 · Week 13 · Construction: Programming, Documenting and Testing

Construction: programming management, documentation and testing

Managing the coding process, system and user documentation, test levels (unit, integration, system, acceptance), black-box and white-box testing, boundary values and writing test cases. The final brings test case table and test type questions.

constructionprogramming managementprogrammer productivitysystem documentationuser documentationreference documentsprocedures manualstutorialstest plantest caseunit testintegration testsystem testacceptance testalpha testbeta testblack-box testingwhite-box testingequivalence partitioningboundary value analysiscyclomatic complexityregression testingstubdriver

Design is finished, and it is the turn of construction: code is written, tested and documented. This phase is usually the part of the project that needs the most people and time. Here the analyst manages and verifies rather than writing code: making sure the programmers work to the same plan, that the tests are tied to the requirements, and that the right document reaches the user. The final exam brings test levels, the difference between black-box and white-box, and the question “write the test cases for this function”.

Golden rules:

  1. Test levels in order: unit → integration → system → acceptance.
  2. Black-box from the specification, white-box from the code.
  3. Test at the boundary: lower − 1, lower, upper, upper + 1.
  4. Every alternate flow is a test case. The descriptions from week 7 are the raw material of the test plan.

Programming management

The project manager’s three jobs in this phase:

1. Assigning tasks to programmers. Modules (packages, classes) are distributed to programmers. Modules that depend heavily on each other are given to the same person or the same small team. As the team grows, the communication load grows (the n(n−1)/2n(n-1)/2 channels of week 3), so “adding people to a late project” doesn’t work.

2. Coordinating activities.

  • Weekly meetings, short progress reports.
  • Standards: naming, coding, comment rules.
  • Code control (source code control / version control): who changed which file, which version was tested. Tools like Git.
  • Three environments: development, test, production. Code moves from one environment to the next in a controlled way.

3. Managing the schedule. The work plan is kept up to date and delays are noticed early. Scope creep is controlled in this phase too: new requests come in via a change request.

Classic mistakes:

MistakeExplanation
Research-oriented developmentThe team tries to learn a new technology it doesn’t know during the project; the schedule slips
Using low-cost personnelA cheap but inexperienced team; the productivity difference is greater than the cost difference
Lack of code controlVersion confusion, overwriting each other’s code
Inadequate testingWhen the schedule gets tight, testing is the first thing cut; then the most expensive errors are found

Documentation

TypeFor whomContent
System documentationDevelopers and the maintenance teamAnalysis and design models, code comments, API documents, installation notes
User documentationEnd usersHow to use the system

The three types of user documentation:

TypeQuestionExample
Reference documents (online help)“What does this function do?”“The Freeze button suspends the membership for up to 30 days.”
Procedures manuals“How do I do this job?”“How to renew a membership: 1. Profile 2. Membership 3. Renew …”
Tutorials“How do I learn the system?”A step-by-step guide on first use

Pros of online documentation: it is searchable, easy to update, and tied to the screen (context-sensitive help). Documents are written in the user’s language: no technical jargon, task-oriented headings (“Make a class reservation”), short steps.

Testing

The test plan

The test plan starts in analysis. Each test case contains this information:

FieldExample
Test IDTC-04
PurposeThe fine must not exceed the book price
PreconditionThe book price is 100 TL
InputdaysLate = 80, isStaff = false
Expected output100.0
Actual output(written during testing)
ResultPass / Fail

Test levels

LevelWhat is testedHowWho
UnitA single class / methodBlack-box and white-boxProgrammer
IntegrationThe modules working togetherUI testing, use scenario testing, data flow testing, system interface testingTest team
SystemWhether the whole system meets the requirementsRequirements, usability, security, performance, documentation testingTest team, analyst
AcceptanceWhether the user accepts itAlpha (test data), beta (real data)Users

Types of integration testing: User interface testing (each interface function), use scenario testing (a use case end to end), data flow testing (does data flow correctly between modules), system interface testing (data exchange with external systems, e.g. the payment provider).

Integration strategies: Top-down (upper modules first, a stub in place of the lower ones), bottom-up (lower modules first, a driver in place of the upper caller), big bang (all at once; hard to find errors).

Types of system testing: requirements testing (is each requirement met), usability testing, security testing, performance testing (load, stress: the 167 requests/s target of week 12), documentation testing (do the steps in the documents really work).

Black-box and white-box

Black-boxWhite-box
SourceSpecification (requirements, description, class contract)Source code
What is examinedInput → expected outputBranches, loops, paths
TechniquesEquivalence partitioning, boundary value analysisStatement/branch coverage, cyclomatic complexity
What it catchesMissing or wrong functionCode that never runs, a wrong branch

Equivalence partitioning: Divide the input space into classes expected to behave the same way, and test one value from each class. Boundary value analysis: test below each boundary, the boundary itself, and above it.

Cyclomatic complexity: The number of independent paths in the code.

V(G)=E−N+2orV(G)=number of decisions+1V(G) = E - N + 2 \qquad \text{or} \qquad V(G) = \text{number of decisions} + 1

EE is the number of edges and NN the number of nodes in the flow graph. At least V(G)V(G) test cases are needed for branch coverage.

Worked example: a fine calculation method

A method from the library system. The rule: 2 TL for each day late; staff pay half price; the fine cannot exceed the price of the book; if there is no delay the fine is 0.

static double fine(int daysLate, boolean isStaff, double bookPrice) {
    if (daysLate <= 0) return 0;
    double f = daysLate * 2.0;
    if (isStaff) f = f / 2;
    if (f > bookPrice) f = bookPrice;
    return f;
}

Step 1: Cyclomatic complexity. Three ifs → V(G) = 3 + 1 = 4. At least four independent paths:

Path 1: daysLate <= 0            → return 0
Path 2: >0, not staff, below the cap
Path 3: >0, staff, below the cap
Path 4: >0, not staff, above the cap

Step 2: Black-box classes and boundaries. For daysLate: ≤ 0 (no fine), ≥ 1 (there is a fine). Boundary: 0 and 1. For the fine: below the price, equal to it, above it.

Step 3: The test case table (bookPrice = 100):

IDdaysLateisStaffExpectedWhat it tests
TC10false0.0Boundary: no delay
TC25false10.0Normal fine (path 2)
TC35true5.0Staff discount (path 3)
TC480false100.0Upper bound: the book price (path 4)
TC51false2.0Boundary: the first day of fine
TC6-3false0.0Invalid/negative input

When you run them all:

System.out.println("TC1 " + fine(0, false, 100));
System.out.println("TC2 " + fine(5, false, 100));
System.out.println("TC3 " + fine(5, true, 100));
System.out.println("TC4 " + fine(80, false, 100));
System.out.println("TC5 " + fine(1, false, 100));
System.out.println("TC6 " + fine(-3, false, 100));
TC1 0.0
TC2 10.0
TC3 5.0
TC4 100.0
TC5 2.0
TC6 0.0

PITFALL · testing only the “happy path”. TC2 passes on its own and makes the method look “correct”. Most errors show up at the boundaries (TC1, TC5), at the limits (TC4) and with unexpected input (TC6).

TIP · test cases from use cases. Every alternate flow in the Reserve Book description from week 7 (2a, 3a, S-1.2a, S-1.3a, 5a) is a system test case. The normal flow is one too: at least 6 test cases are ready.

Common mistakes

Wrong ideaThe truth
Testing starts in implementationThe test plan starts in analysis
Black-box examines the codeIt uses the specification; white-box examines the code
Boundary value = only the boundary itselfBelow it, itself, above it
Stub = driverA stub stands in for the called module, a driver for the caller
Programmers do the acceptance testUsers do
Alpha with real data, beta with test dataThe reverse: alpha is test data, beta is real data
Procedures manual = reference docA reference document describes a function, a procedures manual describes a task
V(G) = number of ifsV(G) = number of decisions + 1

Test yourself

Exam-style questions. Solve them on paper first, then reveal the answer.

Question 1easy

Which test level checks that individual classes or methods work correctly in isolation?

  1. Unit test
  2. Integration test
  3. System test
  4. Acceptance test
Show answer
A) Unit test

A unit test tests a single module (class, method) on its own. An integration test tests the modules working together, a system test tests whether the whole system meets the requirements, and an acceptance test tests whether the user accepts the system.

Question 2easy

Black-box testing designs test cases from what?

  1. The source code structure
  2. The specification (requirements, use case descriptions, class contracts)
  3. Programmer intuition only
  4. The database schema
Show answer
B) The specification (requirements, use case descriptions, class contracts)

In black-box testing you do not look inside the code; the inputs and expected outputs are derived from the specification. In white-box testing, test cases are written by examining the structure of the code (branches, loops, paths).

Question 3medium

A reservation length must be between 1 and 48 hours (integers). Using boundary value analysis, which values should you test?

Show answer
0, 1, 48, 49 (optionally 2 and 47)

Errors concentrate at the boundaries. For each boundary, the value just below, the boundary itself and the value just above are tested: for the lower boundary 0 and 1 (and 2), for the upper boundary 48 and 49 (and 47). 0 and 49 should be rejected, 1 and 48 should be accepted.

Question 4medium

Using equivalence partitioning for the same rule, how many partitions are there?

Show answer
3 (below 1 invalid, 1 to 48 valid, above 48 invalid)

Inputs expected to behave the same way are gathered in one class, and one representative from each class is tested: −5 (invalid), 24 (valid), 60 (invalid). A non-numeric input can also be added as a fourth invalid class.

Question 5medium

What does the method on this page return for fine(30, true, 25)?

static double fine(int daysLate, boolean isStaff, double bookPrice) {
    if (daysLate <= 0) return 0;
    double f = daysLate * 2.0;
    if (isStaff) f = f / 2;
    if (f > bookPrice) f = bookPrice;
    return f;
}
Show answer
25.0

daysLate = 30 > 0. f = 30 × 2.0 = 60.0. isStaff is true → f = 30.0. 30.0 > 25 → f = 25.0. The fine is capped at the price of the book.

Question 6hard

Same method: what does fine(50, false, 100) return, and why is it a good test case?

Show answer
100.0; it hits the boundary where the fine exactly equals the book price.

f = 50 × 2.0 = 100.0. 100.0 > 100 is false, so f does not change: 100.0. If >= were mistakenly written at the boundary (equality) instead of >, the result would be the same, but you would see the difference with 51 days; the equality and one more are tested together.

Question 7medium

What is the cyclomatic complexity of the fine() method?

Show answer
4

There are three decision points (three ifs). V(G) = number of decisions + 1 = 4. From the flow graph too: in a graph with a single exit, 12 edges and 10 nodes → 12 − 10 + 2 = 4. In white-box testing at least 4 independent paths should be tested.

Question 8easy

A method has 4 if statements and 1 while loop (no compound conditions). What is its cyclomatic complexity?

Show answer
6

Each if and each loop is a decision point: 4 + 1 = 5 decisions. V(G) = 5 + 1 = 6.

Question 9medium

During integration testing, module A calls module B, which is not written yet. What do you use in place of B?

  1. A driver
  2. A stub
  3. A beta tester
  4. A regression test
Show answer
B) A stub

A stub is a simple fake module that stands in for a module that has not yet been written and is called (top-down integration). A driver, in contrast, is test code that stands in for a module that has not yet been written and does the calling (bottom-up integration).

Question 10medium

Acceptance testing done by users at the developer's site with test data is called what? And when done at the user's site with real data?

Show answer
Alpha test; beta test

Alpha test: users try the system in a controlled environment with test data. Beta test: users use the system in the real environment with real data and report problems. Both are part of acceptance testing.

Question 11medium

Which document type helps a user complete a specific business task step by step, such as 'How to renew a membership'?

  1. Reference document
  2. Procedures manual
  3. Tutorial
  4. System documentation
Show answer
B) Procedures manual

A reference document: explains what a function does (online help). A procedures manual: explains how to do a business task from start to finish. A tutorial: teaches the system. System documentation is for developers and maintainers.

Question 12easy

Why is regression testing needed after fixing a bug?

Show answer
To make sure the fix did not break parts of the system that worked before.

A change may break other places. Regression testing is re-running the tests that passed before. An automated test suite (unit tests) is valuable for this reason.

Verification: The expected outputs of all test cases of the fine() method were run with the JDK (java verify/SEN2022/Fine13.java). Cyclomatic complexity was computed in node both as V(G) = E - N + 2 and as number of decisions + 1; the boundary value and equivalence class lists are in the same file (verify/SEN2022/13.mjs). Conceptual questions were compared with the standard test level and documentation definitions.

Review card

Programming management: assign tasks, coordinate (code control, standards), track the schedule Classic mistakes: research-oriented development, low-cost personnel, no code control, inadequate testing Documentation: system (for developers) vs user (for users) User doc: reference (what it does), procedures manual (how to do it), tutorial (teaches) Test levels: unit → integration → system → acceptance (alpha, beta) Black-box: from the specification; White-box: from the code (branches, paths) Equivalence class: one representative from each class Boundary value: lower-1, lower, upper, upper+1 (1..48 → 0,1,48,49) Cyclomatic: V(G) = E - N + 2 = decisions + 1 Stub = stands in for the called module (top-down); Driver = stands in for the caller (bottom-up) Regression: re-run the old tests after a fix Test case: ID, purpose, precondition, input, expected output, actual output, result