18.4. Calculation TestsWe now focus on design ideas and smells that apply to calculation tests expressed with ColumnFixture and CalculateFixture. 18.4.1. Smell: Many ColumnsA ColumnFixture or CalculateFixture with many columns may indicate that something is wrong. Is there a tangle of tests here (see Section 18.2.8)? If so, can they be split into separate tests with distinct tables? Are there many repeats in a big table? If so, maybe they can be eliminated by breaking the table up into several smaller tables, with common column values expressed as arguments. For example, one such table from Section 16.3 on p. 131 is shown again as Figure 18.12. Figure 18.12. Table with Arguments18.4.2. Smell: Not CalculatingConsider the table shown again in Figure 18.13. This table is using the form of calculation tests, but the intent is to set up for an action test. It's clearer to use a SetUpFixture table, as shown in Section 10.4 on p. 76.
ColumnFixture tables can also be used for actions tests. For example, the ColumnFixture table in Figure 18.14 is testing that a rental return leads to the correct refund. The returns() column checks that the return succeeded; the running total() column checks the amount of the refund. This test can be expressed a little more clearly by using a DoFixture table without being confused as a calculation test.
18.4.3. Smell: Many RowsAs we've already seen (Section 18.2.10), long tables may need to be organized into several tables to help the test reader and the writer. For example, in Section 13.6 on p. 99, we suggested that a separate table be used to define the late-return business rules when the high demand is not zero. Figure 18.12 shows one of several tables that define fair charging, based on time and the various charge rates. In general, long tables can be split to create separate tables for the major cases. Order the rows in the tables clearly to make it easier to see the organization and easier to see whether cases are missing. Use blanks with ColumnFixture rather than repeating the same value down a column. Or use table arguments, as we saw in Section 18.4.1. 18.4.4. Smell: No Related WorkflowFor any business logic that is tested as calculations, we'd expect to see two or more action-based tests to define what happens under the various circumstances. For example, if we have calculation tests that validate some data input, such as a date, we'd expect to see what happens in the workflow when it's valid and when it's not. For example, we have not shown any action tests for the late-returns tests covered in Chapter 13. |
Wednesday, November 18, 2009
Section 18.4. Calculation Tests
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment