Clean Tests

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

Writing Clean Tests - Beware of Magic

Magic is the arch enemy of readable code, and one of the most common form of magic which can be found from our code is a magic number. Magic numbers litters our source code, and transforms it into a pile of unreadable and unmaintainable rubbish. That is why we should avoid magic numbers at all […] Read more

Writing Clean Tests - Naming Matters

When we are writing automated tests for our application, we have to name our test classes, our test methods, fields of our test classes, and the local variables found from our test methods. If we want to write tests which are easy to read, we have to stop coding on autopilot and pay attention to […] Read more