|
Jtest API | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jtest.TestClass
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".
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 |
protected static final java.lang.Object NO_STUB_GENERATED
protected static final java.lang.Object VOID
stubs()
method returns a
void
type.Method Detail |
public static void addEvent(java.lang.String message)
message
to the
"Test Case Input".message
- message that identifies the event.public static void assert(boolean condition)
condition
is true
.
If the condition is false then a "Specification Error" will be reported by Jtest.public static void assert(boolean condition, java.lang.String message)
condition
is true
.
If the condition is false then a "Specification Error" will be reported by Jtest.message
- message to be used in the error reported.public static void assert(java.lang.String message, boolean condition)
condition
is true
.
If the condition is false then a "Specification Error" will be reported by Jtest.message
- message to be used in the error reported.protected static java.lang.Object makeStubObject(java.lang.Class cl)
cl
.
Stub objects are very useful when writting user defined stubs. A stub
object is like any other object, with the following differences: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, ...).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.
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
method
with this signature.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
.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)
.stubs()
method with a first parameter of type Constructor instead of Method. stubs()
method is not defined, no stubs will be used for those members (i.e. Method or Constructor).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.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 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |