JavaLib
 
Tester
 
Overview
Basic Types
User Types
Inexact Values
Sets
Iterable
Traversals
Maps
Random Choice
Range Check
Equivalence
ISame
Exceptions
Constructors
Methods
CheckFail
 
Sources
Downloads
 
TSRJ Home
TSRJ Local

Constructors

The tester also allows the user to test whether a constructor invocation for the given class and with the given arguments throws the expected exception with the message the programmer expects. The tester will report every type of failure - when the constructor fails to throw exception, when the constructor throws and exception of a different type, when the constructor throws an exception of the correct type, but with a wrong message.

An example of such test is shown below:

// A test for exceptions
// -- this code is expected to throw an exception of the given type 
//  but with a different message - and the test should fail
public void testConstructorExceptions(Tester t){    
  /** A test that throws an exception */
  t.checkConstructorException(
    // the test name - information about this test
    "new Date(4000, 10, 29) \n" +     
    "The test should fail: we supplied a wrong message",

    // the expected exception and message
    new IllegalArgumentException(   
      "Invalid yeer in Date."),

    // the class name
    "MyDate",                           

    // the comma-separated argument list ( or no arguments)  
    4000, 10, 29             
    );
}

This tester reports the failure of this test as follows:

Error in test number 2

 correct exception: 
 class: java.lang.IllegalArgumentException
 incorrect message: 

 message produced: Invalid year in Date.
 message expected: Invalid yeer in Date.
 after invoking the constructor for the class MyDate

tester.ErrorReport: Error trace:
	at ExamplesDates.testWithin(Date.java:65)
	at ExamplesDates.main(Date.java:82)

Code sources

Tests for constructor exceptions are included with general exceptions tests.

Here is the source code for this test suite.

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

Complete test results are shown here.


last updated on Mon Apr 4 15:41:12 EDT 2011generated with DrRacket