Mabrouk Mahdhi
1 min readOct 28, 2023

Great question! Relying solely on random values can sometimes miss specific important cases that need to be tested. Let's take a look at an example in C#:

public int SpecialAdd(int a, int b)
{
if (a == 42 || b == 42)
{
return 42;
}
return a + b;
}

In this SpecialAdd method, if either a or b is 42, it returns 42. Otherwise, it returns the sum of a and b.

Here you have four test cases:

  1. a is a fixed value of 42, b is random, and the sum is fixed at 42.
  2. b is a fixed value of 42, a is random, and the sum is fixed at 42.
  3. Both a and b are fixed values of 42, and the sum is fixed at 42.
  4. a, b, and their respective sums are all random.

When we discuss the use of random values in testing, it is important to note that we are not referring to special cases. Special cases should always be tested separately to ensure full coverage and correctness of the code.

--

--

Mabrouk Mahdhi

Microsoft MVP, Author & Senior Technical Consultant @ eBiz Consulting GmbH