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
  • 5
  • 2
    The goal of the higher-level testing should be to ensure that the well-tested individual components are being used together correctly, not to exhaustively repeat their unit tests. Focus on a few tests that give you confidence in the overall behaviour. – jonrsharpe Oct 19 '21 at 22:54
  • Recommended video: https://www.youtube.com/watch?v=VDfX44fZoMc – VoiceOfUnreason Oct 20 '21 at 01:10
  • When using your TV remote, there are a lot of “stages” to end up sending the signal to your TV after you pressed a button. How would you test this behaviour end to end though ? You’d probably do 2 tests, one with battery, the other one with no battery. Well same here, when writing end to end tests you might want to forget everything about the implementation and only think about the observable behaviour from an external point of view. – Steve Chamaillard Oct 20 '21 at 05:59

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
  • 38,972
  • 9
  • 88
  • 121