Jtest API

jtest
Class TestClass

java.lang.Object
  |
  +--jtest.TestClass

public abstract class TestClass
extends java.lang.Object

Base class for all Test Classes.

The test cases are specified by writing a method for each test case. A method in is considered to specify a test case if is a public static void method that starts with the string test. Jtest will invoke all the test methods in the class consecutivelly. The class can have other methods, those methods can be used for example for common procedures used by all test methods.

The correct behavior of the class is specified by using:

    assert (boolean condition, String message);
 
statements. For example:
 public class TestVector extends jtest.TestClass
 {
     public static void testSize ()
     {
         Vector vector = new Vector ();
         vector.addElement ("name");
         assert (vector.size () == 1, "should be 1");
     }
 }
 
If any assertion fails, Jtest will report an error under "Specification and Regression Errors".

If the test case throws an uncaught runtime exception, Jtest will report an error under "Uncaught Runtime Exceptions".

See {install_dir}/examples/dynamic/testclasses for examples.


Field Summary
protected static java.lang.Object NO_STUB_GENERATED
           
protected static java.lang.Object VOID
          Object used to specify that a stubs() method returns a void type.
 
Method Summary
static void addEvent(java.lang.String message)
          Adds an event with the string message to the "Test Case Input".
The only purpose for it is to be able to see when certain events happened while the test case was executing.
static void assert(boolean condition)
          Asserts that condition is true.
static void assert(boolean condition, java.lang.String message)
          Asserts that condition is true.
static void assert(java.lang.String message, boolean condition)
          Asserts that condition is true.
protected static java.lang.Object makeStubObject(java.lang.Class cl)
          Creates a stub object for the class cl.
static java.lang.Object stubs(java.lang.reflect.Method method, java.lang.Object _this, java.lang.Object[] args, java.lang.reflect.Method caller_method, boolean executing_automatic)
          Stubs generator method.

The implementator of this class should write a stubs method with this signature.

Whenever a method external to the class is invoked in the class under test, Jtest will call this stubs() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_STUB_GENERATED

protected static final java.lang.Object NO_STUB_GENERATED

VOID

protected static final java.lang.Object VOID
Object used to specify that a stubs() method returns a void type.
Method Detail

addEvent

public static void addEvent(java.lang.String message)
Adds an event with the string message to the "Test Case Input".
The only purpose for it is to be able to see when certain events happened while the test case was executing.
Parameters:
message - message that identifies the event.

assert

public static void assert(boolean condition)
Asserts that condition is true. If the condition is false then a "Specification Error" will be reported by Jtest.

assert

public static void assert(boolean condition,
                          java.lang.String message)
Asserts that condition is true. If the condition is false then a "Specification Error" will be reported by Jtest.
Parameters:
message - message to be used in the error reported.

assert

public static void assert(java.lang.String message,
                          boolean condition)
Asserts that condition is true. If the condition is false then a "Specification Error" will be reported by Jtest.
Parameters:
message - message to be used in the error reported.

makeStubObject

protected static java.lang.Object makeStubObject(java.lang.Class cl)
Creates a stub object for the class cl. Stub objects are very useful when writting user defined stubs. A stub object is like any other object, with the following differences:

a) The stub object can be an instance of an interface. I.e. the following creates an instance of "Enumeration":
         Enumeration enum = makeStubObject (Enumeration.class);
 
b) Any method invocation or field reference is an stub even if no stub has been defined for it. If no stub has been defined for it a default stub returning the default initialization value for the method return type or field type is used (i.e. null for Object, 0.0d for double, ...).

Stub objects are necessary to be able to test classes that use interfaces for which an implementation has not been written yet. They can be used whenever an object of the interface class needs to be created. They can also be used whenever one wants to create an object of a given type without having to call any specific constructor (i.e. instead of using new java.io.FileInputStream ("what to put here?)", one can use: (FileInputStream) JT.makeStubObject (java.io.FileInputStream.class), this creates a FileInputStream object, but no constructor is called to initialize it.

stubs

public static java.lang.Object stubs(java.lang.reflect.Method method,
                                     java.lang.Object _this,
                                     java.lang.Object[] args,
                                     java.lang.reflect.Method caller_method,
                                     boolean executing_automatic)
Stubs generator method.

The implementator of this class should write a stubs method with this signature.

Whenever a method external to the class is invoked in the class under test, Jtest will call this stubs() method. The stubs() method should decide if a stub should be used for that method or not. If no stub should be used, the method should return NO_STUBS_GENERATED. If the method return type is void, the stubs() method should return VOID.

If a stub should be used for an invocation, stubs() should either, return the value for the stub, or throw the exception that the stub should throw. The return value should be wrapped in an Object if it is a primitive type. For example if stubs() decides that a given external call should return the integer 3, the value returned by stubs() should be: new Integer (3).

To define stubs for constructor invocations, define a stubs() method with a first parameter of type Constructor instead of Method.

If some stubs() method is not defined, no stubs will be used for those members (i.e. Method or Constructor).

When defining stubs() methods, all the parameters except the first are optional. For example one can define a stubs() method of the form: Object stubs (Method method) instead of the longer version.

Stubs are only used for references from within the tested class.

Parameters:
method - external method being invoked.
_this - this Object if an instance method, null otherwise.
args - arguments to the method invocation.
caller_method - method calling method.
executing_automatic - true if executing an automatic Test Case.

Jtest API