Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The test we have built so far has several assertions, but because the assert function throws an error when a test fails, we won’t know whether or not tests following a failing test fail or succeed. For more fine-grained feedback, we can organize our test into test functions. Each test function should exercise only one unit, but it may do so using one or more assertions. For complete control, we can also require each test to only test one specific behavior of a single unit. This means there will be many tests for each function, but they’ll be short and easy to understand, and the test as a whole will provide to-the-point feedback.
A set of related test functions/methods is referred to as a test case. In the case of the strftime function, we can imagine a test case for the whole method, with each test testing a specific behavior of the function through one or more assertions. Test cases are usually organized in test suites in more complex systems. Listing 1.10 shows a very simple testCase function. It accepts a string name and an object with test methods. Every property whose name starts with the word “test” is run as a test method.