0

I am writing tests for an algorithm that is built up of several consecutive stages. Each such stage has its own set of unit tests.

I want to check that the whole algorithm performs as expected, but am not sure how to approach end to end testing correctly.

Say we have stages a, b, c. Lets say for simplicity's sake each such stage has 5 flows, and a unit test for each of them. Each such flow is a branch in the algorithm, so theoretically to achieve total coverage in my E2E tests, I have to write 5^3 tests. In my real algorithm I have a lot more stages. This exponential growth approach seems unreasonable to me. What is the correct way to on the one hand achieve good coverage of the whole algorithm, but on the other hand not spend an unreasonable amount of time writing a huge amount of complex tests?

thanks!

krezno
  • 167

1 Answers1

1

One approach is to use parametized or dynamic tests. You potentially have just one test that the test framework calls multiple times with a different data set each time that exercises different paths through your code.

So as a contrived example, I might test my Plus function multiple times like this:

[TestCase(1, 1, 2)]
[TestCase(0, 0, 0)]
[TestCase(0, -1, -1)]
SomeTest(int a, int b, int expected)
    let result = Plus(a, b)
    asset.Equal(expected, result)
David Arno
  • 39,599
  • 9
  • 94
  • 129