Straightforward: The First Quality of Valuable Tests
Explore the first quality of valuable tests: straightforwardness. Understand how to make tests clear and immediately understandable, with explicit naming and setup. Learn to avoid complexity and dependencies that cause maintenance issues, so your tests remain reliable and easy to fix over time.
Valuable test qualities
A valuable test saves time and effort over the long term, while a poor test costs time and effort. We’ll focus on five qualities that tend to make a test save time and effort. The absence of these qualities is often a sign that the test could be a problem in the future. To turn them into an acronym that is only slightly contrived, we use SWIFT:
- Straightforward
- Well defined
- Independent
- Fast
- Truthful
Let’s explore these in more detail.
Straightforward
A test is straightforward if its purpose is immediately understandable.
Straightforwardness in testing goes beyond just having clean code. A straightforward test is also clear about how it fits into the more extensive test suite. It should test something different from the other tests, and that purpose should be easy to discern from reading the test. That purpose is usually tied to what condition would make the test fail, not what condition would make the test pass.
Example test
Here is a test that is not straightforward:
Where does the 37 come from? It’s part of the global setup. If we were to peek into this fake example’s user ...