JavaLib
 
Tester
 
Introduction
Setup
User's Guide
Tester API
Samples
Javadocs
 
Sources
Downloads
 
TSRJ Home
TSRJ Local

Tester: An Introduction

The library assumes that all methods that invoke tests are defined within one class, typically named Examples though any name may be used. Every test case is constructed as an invocation of the checkExpect method by an instance of the Tester class within a test method defined in the Examples class. Every method in the Examples class with the name that starts with "test" and consumes one argument of the type Tester is considered to be a test method. The tester library identifies all test methods, invokes each of them, and reports the results. The test report starts with the display of all data defined in the Examples class and is followed by a report of the number of tests performed, the number of tests that failed, and a report on every failed test.

Note: For an explanation of the design of tests that involve inexact numbers, please refer to the document Comparing Inexact Values.

The following class:

import tester.*;

class SimpleExamples{
  String hello = "hello";
  String world = "world";
  
  void testStrings(Tester t){
    t.checkExpect(5, new Integer(5));
    t.checkExpect(hello.equals(world), false);
    t.checkExpect(hello.length(), world.length(), "OK");
    t.checkExpect(hello, world, "will fail");
  }
}

produces the following results:

SimpleExamples:
---------------

   new SimpleExamples:1(
    this.hello =  "hello"
    this.world =  "world")
---------------
Found 1 test methods

Ran 4 tests.
1 test failed.

Test results: 
Success in the test number 1

actual:                                 expected:
5                                       5



Success in the test number 2

actual:                                 expected:
false                                   false



Success in the test number 3
OK
actual:                                 expected:
5                                       5



Error in test number 4
will fail
tester.ErrorReport: Error trace:
	at SimpleExamples.testStrings(SimpleExamples.java:11)
actual:                                 expected:
 "hello"................................ "world"

Failed 1 out of 4 tests.
DONE

last updated on Fri Apr 1 14:26:43 EDT 2011generated with DrRacket