Chapter 6. Trustworthiness

 

In this chapter

  • Test smells around code comments
  • Test smells around poor expectation management
  • Test smells around conditional execution

Trust is good and we generally like it when people are trustworthy. We’d prefer to be able to trust people, as it makes a lot of things in life easier. We’d also like to be able to trust our code—which is one of the reasons we write tests—and the trustworthiness of our tests is a big deal for us. Software development is essentially about modifying, evolving, and maintaining code, and if we can’t trust our tests, we can’t be too confident about our code working after even the most seemingly innocent change.

This chapter is a walkthrough of some of the biggest detractors to test trustworthiness, a parade of test smells revolving around the problem of tests not being reliable. The parade starts with different ways that code comments can go bad. Though the ability to annotate your code with comments written in plain English can be a real boon, these comments can easily turn from useful information to misinformation. Sometimes it’s even worse, when the whole body of a test has been commented-out such that the test is still executed and passes with flying colors—but it doesn’t actually do anything.

6.1. Commented-out tests

6.2. Misleading comments

6.3. Never-failing tests

6.4. Shallow promises

6.5. Lowered expectations

6.6. Platform prejudice

6.7. Conditional tests

6.8. Summary