Version: 5.2.1

Introduction

Here is a very simple example of the use of the tester library, together with a sample output from running the tests. _________________________________________________________________________________

For the beginner, the library assumes that all methods that invoke tests are defined within one class, typically named Examples, though any name may be used. (For a more advanced programmer the library supports a number of other options for where the test cases are defined, as well as the type of test cases that are supported.)

Related test cases are defined within a method with the name that starts with test and consumes one argument of the type Tester.

A test case is constructed as an invocation of the checkExpect method by an instance of the Tester class given as the method argument. (Additional test case scenaria may use other similar methods, e.g. checkInexact, checkRange, checkException, etc.)

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.

Here is a very simple example. 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 output: _________________________________________________________________________________

Tester Prima v.1.5.1 - 17 June 2012

-----------------------------------

Tests defined in the class: SimpleExamples:

---------------------------

SimpleExamples:

---------------

 

 new SimpleExamples:1(

  this.hello =  "hello"

  this.world =  "world")

---------------

 

Ran 4 tests.

1 test failed.

 

Failed test results:

--------------

 

Error in test number 4

will fail

tester.ErrorReport: Error trace:

        at SimpleExamples.testStrings(Examples.java:11)

        at SimpleExamples.main(Examples.java:16)

actual:                                 expected:

 "hello".......................................... "world"

 

 

 

--- END OF TEST RESULTS ---

_________________________________________________________________________________

JavaLib Home