Thoughts and opinions about unit tests

What constitutes a good unit test?

The attributes of a good unit test are generally described as:

  1. Isolated: A test must be completely isolated in terms of setup, execution and outcome (the arrange, act and assert steps). In other words, running a test individually or as part of a suite should not change the outcome
  2. Repeatable: One should be able to run a unit test as many times as necessary with consistent results that do not change with unrelated reasons.
  3. Quick: Unit tests ought to provide quick feedback. Hence, they must be fast to run.

How many "Assert" statements are allowed in a unit test?

  1. Test one logical concept per test. If you need to test multiple aspects of the concept, that is perfectly fine.
  2. Think about readability of the test code as well as readability of test output
  • HERE is a great discussion on the number of asserts per unit test

Test Smells

The Test pyramid

Martin Fowler describes the test pyramid

My favourite test frameworks and tools on the .NET Stack

[As of March 2019]

Alternate Test Frameworks