Code Quality Design Help

Finding Test Cases

The following is the process and tools I used to create test cases. For simple methods, I sketch a truth table of the inputs, then analyze each row and write the expected result. I cross out any rows that are impossible or I don't care about. Finally, I create a test case for each relevant row on the table.

static bool Branch(bool a, bool b) { var result = false; if (a) { if (b) { result = true; } } return result; }

a

b

Result

T

T

true

T

F

false

F

T

false

F

F

don't care

There are 4 rows in the truth table, but since when a is false, the value of b does not matter, so we only need 3 test cases.

[TestCase(true, true, true)] // 100% statement coverage [TestCase(true, false, false)] [TestCase(false, true, false)] public void BranchTest(bool a, bool b, bool expected) { Assert.AreEqual(expected, Branch(a, b)); }

The first test case: a = true and b = true gets 100% statement coverage.
But this is only 1/3 or 33% total branch or decision coverage.

When things are more complicated beyond a couple of boolean values, I use a free mind mapping tool to help model the test cases and keep track of testing progress.

Let's say we're creating test cases around t-shirts that have 3 input variables: size, age, and color.

  1. Create a node called Testing Considerations.

  2. Append suitable values for each variable: size (small, medium, large), age (child, adult), and color ( red, blue).

Mind map of Testing Considerations showing size, age, and color branches
  1. Create a node called Tests.

  2. Copy and paste (append) the size branch to the Tests node.

  3. Append the age branch to each size node.

  4. Append the color branch to each age node.

The branch count equals the number of potential test cases.

3 size × 2 age × 2 color = 12.

Mind map of Tests tree enumerating combinations of size, age, and color
  • Often there are constraints that allow us to prune the number of test cases.

    • Example constraints:

      • Child sizes only come in small and large.

      • Adult colors only come in red.

  • After pruning the tree, there are only 7 branches.

  • The order of implanting the nodes (size → age → color) is subjective and may need adjusting.

    • Therefore, I use a mind mapping tool since it allows you to easily modify the tree.

  • Shown here are three possible ways to create the Tests tree. The one you end up with depends on experience and ordering.

Alternative Tests tree arrangement demonstrating constraints (version 1)
Alternative Tests tree arrangement demonstrating constraints (version 2)
Alternative Tests tree arrangement demonstrating constraints (version 3)

Equivalence Partitioning

Equivalence partitioning divides the input domain of a variable into groups, called equivalent classes, that represent interesting conditions. We expect two values of a variable belonging to the same equivalent class to produce the same test results (pass or fail).

An input variable has certain ranges of valid and invalid values. For example, an int variable for month ranges from 1 to 12, so any value less than 1 or greater than 12 is invalid.

For another example, say we want to compare two lists. There might only be 3 classes to consider:

  • All items in one list match the items in the other list.

  • Some items match.

  • None of the items match.

Equivalence partitioning can be subjective and application-dependent. Given an input variable, different people may produce distinct sets of valid and invalid classes for different applications. (Dianxiang 350)

When generating Testing Considerations, you don't need to include every possible value that an input variable can take. Use equivalence partitioning to generate a manageable subset of interesting values and be sure to include values for the happy path and the error path.

Example
MySqrt() has an infinite (∞) number of input values but only about 3 interesting ones.

static double MySqrt(double x) { if (x < 0) { return -1; } return Math.Sqrt(x); }
Diagram of MySqrt input classes: negative returns -1; zero and positive use Math.Sqrt(x)
MySqrt test cases highlighting three equivalence classes: x < 0, x = 0, x > 0

After I'm finished with creating the Testing Considerations and Tests branch, I add the result or expected value leaf to the end of each test branch.

  1. At the end of each test branch, add a leaf that contains the expected test results.

  2. As you add or run each test, mark each leaf to help keep track of your progress.

Mind map showing result leaves attached to each test branch

Real World Examples

Screenshot of HCM viewer showing URL example used in real-world testing
Screenshot listing multiple test scenarios for the application

Back in the Garmin Days

Garmin project screenshot 1 illustrating test case mapping during development
Garmin project screenshot 2 showing additional test branches and results
Garmin project screenshot 3 summarizing test execution progress

See Also:

20 August 2025