Section 38.4. Summary


38.4. Summary

It can be well worthwhile to create custom fixtures so that Fit tables can express tests directly and clearly. We have looked at the development of two example fixtures:

  1. SetUpFixture, which is used to add the data from the rows of the table to set up the elements of a collection

  2. ImageFixture, which checks the names of images in the table against a 2D array of expected names

Listing 38.3. ImageFixture.java
 public class ImageFixture extends Fixture {     private String[][] actual;     public ImageFixture(String[][] actual2DArrayOfImageFileNames) {         actual = actual2DArrayOfImageFileNames;     }     public void doTable(Parse table) {       if (actual.length == 0 && table.parts.more == null)          right(table.parts);       else if (!rowsMatch(actual, table.parts))          addActualRows(table.parts,actual);     }     private boolean rowsMatch(String[][] actual, Parse lastRow) {        boolean matched = true;        for (int i = 0; i < actual.length; i++) {           lastRow = lastRow.more;           if (!cellsMatch(actual[i],lastRow.parts))              matched = false;        }        return markWrong(lastRow.more, matched);     }     private boolean cellsMatch(String[] actual, Parse allCells) {        Parse cells = allCells;        boolean matched = true;        for (int i = 0; i < actual.length; i++) {           if (!cellMatches(actual[i], cells))              matched = false;           cells = cells.more;        }        return markWrong(cells, matched);     }     private boolean cellMatches(String actual, Parse cell) {        if (cell.body == null)           return false;        String image = getImageFileName(cell.body);        boolean matches = finalFileName(actual).equals(finalFileName(image));        if (matches)           right(cell);        else           wrong(cell);        return matches;     }      // ...   } 



    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