Section 21.4. ColumnFixture in General


21.4. ColumnFixture in General

We can now state the operation of ColumnFixture in more general terms. When it runs a table, Fit creates an object of the fixture class named in the first row, calling the method doTable() of that fixture object.

For a ColumnFixture type of table, doTable() in fit.ColumnFixture reads the labels in the header row of the table to determine the order of the columns. For each cell in the header row, working from left to right, doTable() determines the type of column label for that cell and creates a suitable object of class TypeAdapter[2] for that column. For a given label:

[2] TypeAdapter is discussed further in Chapter 25.

  • The TypeAdapter uses the label to find the corresponding instance variable of the fixture object and thus its type.

  • However, if the instance variable is missing or is not public, an exception is thrown and is reported in the cell.

For a calculated label:

  • The TypeAdapter uses the label to find the corresponding method of the fixture object and thus its return type.

  • However, if the method is missing, is not public, or takes arguments, this is reported in the cell.

Below the header row, working down each test row, and for each cell, working from left to right, it uses the TypeAdapter for that column.

  • For a given label, it uses the TypeAdapter to convert the value in the cell and assign it to the instance variable of the fixture object.

  • For a calculated label, it uses the TypeAdapter to (1) call the method of the fixture object, getting the result; (2) take the expected text value from the cell and convert it into a value of the return type; and (3) compare the value that was returned from the method against the expected result. If they match, the cell is colored green. If they do not match, the cell is colored red, and the actual result is added to the cell in the report. However, any exception thrown by the method call is reported in the cell.

Questions & Answers

Q1:

What if a cell is empty?

A1:

If a given cell is empty, the current value of the corresponding instance variable is reported in that cell. If it's a calculated cell, the value returned by the corresponding method is reported.

Q2:

But what if the given value was intended to be the empty string?

A2:

Use the special word blank for this case. However, if this also clashes, you'd need to choose a special String value to represent an empty string, such as ((EMPTY)). Then test for that value in the fixture code, and use an empty String instead in any calls into the system under test.

Alternatively, you could use CalculateFixture, which doesn't necessarily process empty cells in a special way. CalculateFixture is discussed in Section 28.8 on p. 242.



    Fit for Developing Software. Framework for Integrated Tests
    Fit for Developing Software: Framework for Integrated Tests
    ISBN: 0321269349
    EAN: 2147483647
    Year: 2005
    Pages: 331

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net