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
Clean Tests
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
Automated tests are worthless if they don’t assert anything, but the problem of regular JUnit assertions is that they speak the wrong language and become messy if we have to write a lot of them. If we want to write tests which are both easy understand and maintain, we have to figure out a better […] Read more
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
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
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