Skip to content
Tutorials Center
My learning

Topics

Lesson 57 of 60 ยท Practice and Interview Prep

Practice Exercises with Solutions

Five hands-on software testing exercises with worked answers: equivalence partitions and boundaries, decision tables, state transitions, bug reports and risk ranking.

You learn test design the way you learn to cook: by doing it with real ingredients. This lesson gives you five exercises, one for each major skill in the track. Each has a short specification, a space to try it yourself first, and a worked solution that you can compare with your own.

The advice that makes this lesson work is simple: do not read the solution until you have written down your answer on paper. A wrong answer you reasoned about teaches more than a right answer you read. After each solution there is a small runnable stand-in that checks the answer against code, so you can see the reasoning verified instead of taking it on trust.

Five exercises, five skills

  1. Partitions and boundaries
Which inputs do you try?
  1. Decision table
Which combinations of conditions?
  1. State transitions
Which moves are valid and invalid?
  1. Bug report
Can someone else reproduce it?
1 / 2

Exercise 1: equivalence partitions and boundary values

Specification. A cinema sells tickets based on age. Valid ages are whole numbers from 0 to 120. Ages 0 to 2 are free, ages 3 to 12 pay a child price ($6), ages 13 to 64 pay the adult price ($12), and ages 65 and over pay the senior price ($8). Any other input is rejected.

Task. List the equivalence partitions, then choose boundary test values. How many tests do you need?

Try it yourself first. Draw a number line from -5 to 125 and mark where the behaviour changes.

Solution

The valid partitions are free (0-2), child (3-12), adult (13-64) and senior (65-120). The invalid partitions are below the range (negative numbers), above the range (121 and up) and not a whole number at all (a fraction such as 2.5, or text such as "abc"). That makes four valid and four invalid partitions.

Equivalence partitioning alone needs one value per partition, so 8 tests. Boundary value analysis adds the values on each edge. Each boundary needs the last value of one partition and the first of the next: -1 and 0, 2 and 3, 12 and 13, 64 and 65, 120 and 121. That gives 10 numeric values: -1, 0, 2, 3, 12, 13, 64, 65, 120, 121, plus the two non-numeric partitions ("abc" and 2.5) for a total of 12 tests. The middle value of each valid partition (say 8, 30, 90) is now optional, because the boundaries already represent each partition.

JS Check the boundary tests and catch an off-by-one

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The planted bug treats 12-year-olds as adults. A test with age 8 would never find it. Only the boundary value 12 does, which is the entire argument for the technique.

Exercise 2: a decision table

Specification. An online shop charges for delivery like this. If the address is in a remote area, the fee is $9.00, whatever else is true. Otherwise delivery is free for members and for orders of $30.00 or more. Everyone else pays $4.00.

Task. Build the full decision table, then collapse it. How many rules are left?

Try it yourself first. The conditions are remote, member and order is $30.00 or more. How many combinations exist?

Solution

Three yes/no conditions give 2 x 2 x 2 = 8 combinations. Collapse the rules that have the same outcome by marking an input as "don't care" (-). If the area is remote, the other two conditions do not matter. If it is not remote and the customer is a member, the order size does not matter. That leaves four rules, as in decision table testing:

Rule Remote Member Order $30+ Fee
R1 yes - - $9.00
R2 no yes - $0.00
R3 no no yes $0.00
R4 no no no $4.00

A collapsed table is only correct if it is complete (every combination matches a rule) and consistent (no combination matches two rules with different outcomes). The stand-in checks both properties by expanding all eight combinations, then compares the shop's code with the table, including the order total of exactly $30.00 that the rule calls out.

JS Expand the collapsed table and test the code

Press Run (or Ctrl + Enter) to see the console output here.

No output.

All eight combinations are matched by exactly one rule, so the table is complete and consistent. The buggy version fails only for non-members with exactly $30.00, a boundary hiding inside a decision table: another reminder that techniques combine.

Exercise 3: state transitions

Specification. A library book is Available, OnLoan, Reserved or Lost. A member can borrow an Available book (it becomes OnLoan) or reserve it (Reserved). An OnLoan book can be returned (Available) or reported lost (Lost). A Reserved book can be borrowed, by the member who reserved it, and becomes OnLoan. Lost is final.

Task. Build the state table. How many cells does it have, how many are valid, and how many tests do you need for 0-switch coverage plus the invalid cells?

Try it yourself first. Write the four states down the side and the four events across the top, then fill every cell with a state or "rejected".

Solution

The table has 4 x 4 = 16 cells. Only 5 are valid transitions (Available: borrow, reserve; OnLoan: return, lose; Reserved: borrow). The other 11 must be rejected without changing the state. So you need 5 tests for 0-switch coverage and 11 negative tests, 16 in total. For history-dependent bugs you can also add selected two-step sequences, such as borrow then return.

JS Print the state table and count sequences

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The answers match: 16 cells, 5 valid, 11 invalid, and 7 two-step sequences. Notice that the specification never says what happens when you reserve a book that is already Reserved, or return a book that is Available. Both are invalid cells, and writing them down is exactly how this technique uncovers missing requirements. In a real project you would ask the product owner.

Exercise 4: rewrite a bug report

Here is a report from a colleague.

TEXT
Title:   Search is broken
Steps:   Use search
Actual:  It doesn't work

Task. List what is missing, then rewrite it as a report a developer could act on. Assume you tried the search box on the product list page, typed "Cafe" and expected to see the book "Cafรฉ Society" (the real title has an accented letter), and no results were shown.

Try it yourself first. Imagine you are the developer, new to the project, and you must reproduce it from the report alone. What do you need?

Solution

The original lacks a specific title, reproducible steps, an expected result, an environment and a severity. "It doesn't work" is the weakest possible description of the actual result, because it does not say what happened. A better version, following Writing Excellent Bug Reports:

TEXT
Title:        Product search returns no results for a title typed without its accent
Environment:  Staging, build 2.4.1, desktop browser, test account
Steps:        1. Open the product list page
              2. Type "Cafe" in the search box and press Enter
Expected:     "Cafรฉ Society" appears in the results (the title contains an accented letter)
Actual:       The page shows "No results found"; the same search with the accent works
Severity:     Minor (a workaround exists: type the accent)
Priority:     Medium (affects many users who cannot type accents)

The stand-in lints both reports against a short checklist. A linter can only check that the parts exist, not that they are good, and the output will show that limit.

JS Lint the weak and the improved report

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Look at "Actual result given" for the weak report: it passes, although "It doesn't work" tells nobody anything. A human reviewer is still needed for quality. The linter is useful for catching missing parts early, which is most of the problem in real reports.

Exercise 5: rank by risk

Specification. A concert ticket site is about to release. The features are seat selection, payment, email confirmation, discount coupons and the newsletter sign-up. You have time for deep testing of two of them.

Task. Give each feature a likelihood and an impact from 1 to 5, compute the risk score, and decide where the deep testing goes. Justify each number in one phrase.

Try it yourself first. Think about what happens to money, to customers and to the company if each feature fails.

Solution

Your numbers may differ from the ones below, and that is fine, because ratings are judgments. What matters is the reasoning. Here is one defensible set, as in risk-based testing:

Feature Likelihood Impact Score Reason
Payment 3 5 15 Money moves, new provider
Seat selection 3 4 12 Double-booked seats are costly
Discount coupons 4 2 8 Changed often, small loss per failure
Email confirmation 2 3 6 Stable, but customers need the ticket
Newsletter sign-up 2 1 2 Failure is a nuisance

Deep testing goes to payment and seat selection. The stand-in ranks the features and then shows how the ranking reacts to new information, which is the real value of writing the numbers down.

JS Rank the features and re-rank after news

Press Run (or Ctrl + Enter) to see the console output here.

No output.

When the impact of coupons rises, they jump to the top of the list (20 against 15), and the deep testing moves with them. Risk ranking is not done once: it is updated when you learn something new about the product, the code or the users.

How to use these exercises

  • Time yourself. Interviews often give you 10 minutes for a technique question. Practice exercise 1 in that time.
  • Change the specification. Move a boundary, add a condition, add a state, and redo the exercise. Variation is where understanding grows.
  • Explain your answers aloud. If you can explain why 12 and 13 are your boundary tests, you understand them.
  • Write the missing requirement. For every exercise, find one question the specification did not answer. This is a real tester's superpower.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Valid ages are 0 to 120. Which values give boundary tests for the upper edge?

    The upper boundary is between the last valid value (120) and the first invalid value (121), so those two are tested.
  2. 2. A decision table has 4 conditions with yes/no values. How many combinations does the full table contain?

    Each condition doubles the count: 2 x 2 x 2 x 2 = 16.
  3. 3. A state model has 3 states and 5 events. Only 4 cells are valid transitions. How many cells must be tested as invalid?

    The table has 3 x 5 = 15 cells. With 4 valid, 11 are invalid, and each should be rejected without changing the state.
  4. 4. Which bug-report title is the most useful?

    A good title names the symptom and its trigger, so the report can be found, understood and prioritized without opening it.
  5. 5. Why can two testers give different likelihood and impact numbers and both be reasonable?

    Risk ratings estimate unknowns. A clear justification can be reviewed and changed when new information arrives.

Summary

  • Partition first, then add boundary values on both sides of each edge; the boundary values usually find the bugs.
  • A decision table with n yes/no conditions has 2^n combinations; collapse them with don't-care entries and check the result is complete and consistent.
  • A state table with S states and E events has S x E cells; most are invalid, and each needs a test that checks the state does not change.
  • A good bug report lets a stranger reproduce the problem: specific title, steps, expected and actual results, environment, severity.
  • Risk scores guide what to test first, and the ranking should be revisited whenever you learn something new.

Continue with Software Testing Interview Questions.