Methods

Tests to check the expected value produced by a method invocation.

Overview

The tester defines the method checkMethod that allows the programmer to test the expected value produced by a method invocation by providing the expected value, the instance that invokes the method, the method name, and the arguments that the method consumes. If the expected object contains inexact value the programmer must use the checkInexactMethod variant of the method.

The class ExamplesMethods contains all test cases.

Code sources

Here is the complete source code for this test suite.

You can also download the entire souce code as a zip file.

Complete test results are shown here.

Brief Examples

Here is an example that illustrates both versions.

public class ExamplesMethods {
    Song song1 = new Song("title1", 4);
    Song song2 = new Song("title2", 2);
    Song song1a = new Song("title1", 4);

    CartPtDouble pt = new CartPtDouble(3.0, 4.0);

    public void testMethod(Tester t) {
	t.checkMethod("Success: Check if you get the shorter song",
	    this.song2,       // expected value
	    this.song1,       // object that invokes the method
	    "shorter",        // method name

        t.checkMethod("Should fail: Check if you get the shorter song",
	    this.song1,       // expected value
	    this.song1,       // object that invokes the method
	    "shorter",        // method name
	    this.song2);      // method arguments
    }

    public void testInexactMethod(Tester t) {

	t.checkInexactMethod("Success: Inexact check",
	    4.998,
	    0.001,
	    this.pt,
	    "distTo0");

	t.checkInexactMethod("Should fail: Inexact check",
	    4.998,
	    0.0001,
	    this.pt,
	    "distTo0");

	t.checkInexactMethod("Success: Inexact check",
	    4.998,
	    0.001,
	    this.pt,
	    "distTo",
	    new CartPtDouble(7.0, 7.0));
    }
}

back

Last updated: April 1, 2011 11:41 am