chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male

Avoid logic inside a unit test

Why?

Unit tests that have logic can also have logic related bugs. The worst thing you can do is to have a bug in your test since that is the hardest bug to find. It’s hard to find because you usually assume your test is OK and unless you are doing true Test Driven Development, you are likely to find that bug much later in time after you’ve searched for the possible problem in the production code under test.

also, having logic in a test can usually mean that you are testing more than one thing – in that case, it is better to separate the single test into multiple different tests, each testing a different aspect of the original test. that would also make the test naming easier.

Possible types of logic inside a test may include:

  • If\Else
  • Switch\Case
  • Loops