Tests should be cohesive, independent, and isolated

Tests should be as cohesive, independent, and isolated as possible. Ideally, a single test method should test a single functionality or behavior of the system. Fat tests (or, as the test smells community calls them, eager tests) exercise multiple functionalities and are often complex in terms of implementation. Complex test code reduces our ability to understand what is being… Continue reading Tests should be cohesive, independent, and isolated

Tests should be fast

Tests are a developer’s safety net. Whenever we perform maintenance or evolution in source code, we use the feedback from the test suite to understand whether the system is working as expected. The faster we get feedback from the test code, the better. Slower test suites force us to run the tests less often, making… Continue reading Tests should be fast

Principles of maintainable test code

What does good test code look like? There is a great deal of literature about test code quality, which I rely on in this section. Much of what I say here can be found in the works of Langr, Hunt, and Thomas (2015); Meszaros (2007); and Beck (2019)—as always, with my own twist.

Introduction

You have probably noticed that once test infected, the number of JUnit tests a software development team writes and maintains can become significant. In practice, test code bases grow quickly. Moreover, we have observed that Lehman’s law of evolution, “Code tends to rot, unless one actively works against it” (1980), also applies to test code. A… Continue reading Introduction