Section 39.3. Reading Tests from a Text File


39.3. Reading Tests from a Text File

Listing 39.1 shows the class SumRunner which processes the comma-separated test files, mapping the test into Fit. The main() method of the class expects two arguments: the input and report file names.

The constructor of SumRunner passes three things to the superclass: the title of the HTML file that's to be produced; the input File, so that the file details can be added to the fixture; and the name of the report file. The constructor then calls makeTable() to read the input file and create the internal form of the Fit tables required. Then the tests are run and reported with a call to the runAndReportAndExit() method of the superclass, CustomRunner. This method runs Fit on the internal tables, writes the report, prints the count information to System.err, and exits with a suitable error code.

Listing 39.1. SumRunner.java
 public class SumRunner extends CustomRunner {    public static void main(String args[]) throws IOException {       if (args.length != 2) {          System.err.println(          "Usage: java SumRunner inputFile.txt reportFile.html");          System.exit(-1);       }       new SumRunner(new File(args[0]),args[1]);    }    public SumRunner(File inFile, String reportFileName)                          throws IOException {       super("Sum",inFile,reportFileName);       BufferedReader in = new BufferedReader(                       new FileReader(inFile));       makeTable(in);       runAndReportAndExit();    }    private void makeTable(BufferedReader in) throws IOException {      addTable("Sum");      addRow("a | b | sum()");      while (true) {         String line = in.readLine();         if (line == null)            break;         addRow(line);      }      addTableWithLeaderText("fit.Summary","<BR>");    } } 

The method makeTable() in Listing 39.1 calls the inherited addTable() to create a new table with the first row value as argument. The method addRow() creates a new row in the table. Finally, the second table is added, a fit. Summary, with the text "<BR>" included before the table so that the tables are separated in the report. Other functionality to ease writing custom runners is provided in class CustomRunner; see the code for details.

Questions & Answers

Q1:

Is the report always provided as HTML?

A1:

The Fit output need not be provided in HTML, although that is usually convenient. It would be possible to walk over the Parse TRee, after the tests have been run, and produce some other output format; we don't consider that further here.

Q2:

What if the test data file is huge?

A2:

In that case, building huge Parse trees may consume too much memory. It may be better, in the case of ColumnFixture tables, to produce several smaller tests and run them in sequence.



    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