Say we wanted to test division to see if it is acceptable. (We normally test more complicated things, things that we can control, but this is a simple example.)

We will make two things to complete our test. The first is a description of what we want including a tabular list of test cases that we believe will show that division is working acceptably.


Part 1 -- The Specification

We want division that works with positive and negative numbers.

eg.Division
FIND-CLASS: EG.DIVISION does not name a class
numerator denominator quotient()
1000 10 100.0000
-1000 10 -100.0000
1000 7 142.85715
1000 .00001 100000000
4195835 3145729 1.3338196

This last case is the famous pentium bug. See http://www.cs.earlham.ed ... o/cs63/fdiv.html.


The second thing we make is a "fixture" that can take the data provided in the table and compute the expected results. The fixture is a java program that can perform the operations that we want to test.


Part 2 -- The Fixture

  public class Division extends ColumnFixture {
    public float numerator;
    public float denominator;
    public float quotient() {
      return numerator / denominator;
    }
  }


Our two parts, the specification and the fixture, are connected by the fact that the table names the fixture (Division) in its first cell. The Division fixture knows how to make sense of the table because it extends a class that already does. A column fixture looks for variables and methods it might have that match the column headings in the table.

After we've prepared these two parts and put them into appropriate files, we run the test to produce results, a copy of our input with right and wrong answers noted.

  c: java FileRunner input.html results.html
  7 right, 0 wrong, 0 ignored, 0 exceptions

The c2.com server can retrieve this page and run these tests for you using a simple RunScript. Click the following link and wait a few seconds for the results to appear. You will see the same page, except that the Quotient column has turned green. That tells you that the actual results match the expected results.

This completes our simple example. A good next step would be to try the CalculatorExample or DownloadNow and explore the prepared example described in RunMeFirst.