Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

14. Testing and Readability > What Was Wrong with That Test? - Pg. 159

void Test_SortAndFilterDocs_NegativeValues() { ... } ... Don't be afraid of having a long or clunky name here. This isn't a function that will be called throughout your codebase, so the reasons for avoiding long function names don't apply. The test function name is effectively acting like a comment. Also, if that test fails, most testing frameworks will print out the name of the function where the assertion failed, so a descriptive name is especially helpful. Note that if you're using a testing framework, there might already be rules or conventions on how methods are named. For instance, the Python unittest module expects test method names to start with "test." When it comes to naming helper functions in your test code, it's useful to highlight whether the function does any assertions itself or is just an ordinary "test-unaware" helper. For instance, in this chapter, any helper function that calls assert() is named Check...() . But the function AddScoredDoc() was named just like an ordinary helper function. What Was Wrong with That Test? At the beginning of the chapter, we claimed there were at least eight things wrong with this test: