Chapter 17. Odds and ends

 

This chapter covers

  • Testing file-based features without disrupting the file system
  • Testing the syntax of your tests
  • Customizing assertions for test readability
  • Testing hidden behavior

There are always a few more things that authors want to say, but cannot find the appropriate chapter in which to say them. At that point, there are essentially two options: leave those things out of the book or create a catchall chapter in which to put them. We opted for the latter. This chapter contains recipes that simply did not make their way into one of the other chapters, for one reason or another.

We do not recommend writing tests that rely heavily on the file system; but if you need to do it, then we provide a recipe that describes some of the unexpected problems with cleaning up files between tests (see recipe 17.1, “Clean up the file system between tests”). We further describe one way to reduce the degree to which your tests depend on the file system in recipe 17.2, “Test your file-based application without the file system.”

Some of the problems that novice JUnit users experience have to do with incorrect JUnit syntax. We see at least one or two such messages on the mailing lists per month. In recipe 17.3, “Verify your test case class syntax,” we describe a tool that helps you avoid spending time hunting down a problem related to a typo, rather than a “real” problem. If you have to program alone, then this recipe helps eliminate one source of problems.

17.1. Clean up the file system between tests

17.2. Test your file-based application without the file system

17.3. Verify your test case class syntax

17.4. Extract a custom assertion

17.5. Test a legacy method with no return value

17.6. Test a private method if you must