1

I am thinking, if I do proper testing for all methods in all my classes, then - disrgegarding UI - do I still need system testing? I mean, what would a simple example be, showing a case where unit testing is not necessary to reveal some errors? I tried to come up with something but failed, it always could have been caught at unit level.

5

2 Answers 2

3

Think of it this way:

  • Unit tests validate implementation
  • Integration tests validate design
  • Behaviors (BDD) validate specifications

You can have your one unit tested to 100% coverage documenting at least one reason for every line and branch you have in that unit. Then you combine that unit with something else that had different expectations for how your unit behaves. Behold an error in the design.

2
  • 1
    I upvoted this, even though I disagree with your bullet 2, because your answer provides clarity. But Wikipedia disputes your definition of "system testing," and not all shops use BDD. Apr 25, 2018 at 17:16
  • I'm well aware that not all shops use BDD, but that is it's purpose. I think I wrote System tests when I meant to write Integration tests. I will change the working to indicate that. Apr 25, 2018 at 19:24
1

Any interaction between the 'Units' of your unit test cannot be tested, whatever you choose as 'Unit'.

Imagine you are building a car, and you unit-test the engine and the wheels (and they pass). You now have a well-working engine, and well-working wheels.
If you now mount the engine on the outside of one wheel, your car will probably fail - because the issue is in the interaction between the units.

That's why there are integration tests.

2
  • Well, if I test properly all the inputs and outputs of individual units (i.e. their interface), then the interaction of units should be easy as it uses them.
    – John V
    Apr 25, 2018 at 16:45
  • The short answer is "No - it isn't easy". You make assumptions about "test properly", and that is well-known to be erroneous. If your wheels are rated for a particular horsepower, but the interface to the wheels does not specify the maximum horsepower, it is easy to build a non-working system by adding an overpowered engine. Apr 25, 2018 at 16:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.