Clean Tests

Writing Clean Tests - Small Is Beautiful

We have learned that "clean" unit tests might not be as clean as we think. We have done our best to make our unit tests as clean as possible. Our tests are formatted properly, use domain-specific language, and avoid excessive mocking. Nevertheless, our unit tests are not clean because: When we make changes to the […] Read more

Writing Clean Tests - Trouble in Paradise

If our code has obvious faults, we are very motivated to improve it. However, at some point we decide that our code is "good enough" and move on. Typically this happens when we think that the benefits of improving our existing code are smaller than the required work. Of course, if we underestimate our return […] Read more

Writing Clean Tests - To Verify Or Not To Verify

When we write unit tests that use mock objects, we follow these steps: Configure the behavior of our mock objects. Invoke the tested method. Verify that the correct methods of our mock objects were invoked. The description of the third step is actually a bit misleading, because often we end up verifying that the correct […] Read more

Writing Clean Tests - Divide and Conquer

A good unit test should fail for only one reason. This means that a proper unit test tests only one logical concept. If we want to write clean tests, we have to identify those logical concepts, and write only one test case per logical concept. This blog post describes how we can identify the logical […] Read more

Writing Clean Tests - New Considered Harmful

Creating new objects is an essential part of automated testing, and the most obvious way to do it is to use the new keyword. However, this is not the best way to create new objects in our test cases, and using the new keyword will make our tests harder to read and maintain. This blog […] Read more