|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object testing.Examples
public class Examples
The parent of Example/Test classes.
In order to use the Examples
class, you simply import it, and create your own examples
class that extends Examples
, and insert the
following stub method at the top:
public static void main(String[] args){ test(); }When you run your examples class in Eclipse, this method will start the create an instance of your examples class, print it, and run any test methods (methods who's names begin with test). The resulting report can be used to verify that your tests pass, or see where any checkExpects failed.
In order to test specific classes and methods, you can use the appropriate checkExpect methods. Specially named test method i.e., testFoo return a number of checkExpects combined with && (anded together).
Below is a sample, which demonstrates most of the testing features:
import testing.Examples; public class FooExamples extends Examples{ public static void main(String[] args){ test(); } Foo f1 = new Foo("hello"); Foo f2 = new Foo("Jimmy"); Bar b1 = new Bar(f1); Bar b2 = new Bar(f2); boolean testFoo(){ return (checkExpect(f1.s, "hello") && checkExpect(f2, new Foo("Jimmy")) && checkExpect(f2.i, 5)); } boolean testBar(){ return (checkExpect(b1.getFoo().s, "hello") && checkExpect(b2.getFoo(), new Foo("Jimmy")) && checkExpect(b2.getFoo().i, 5)); } } class Foo{ int i = 5; String s; Foo(String s){ this.s = s; } } class Bar{ Foo f; Bar(Foo f){ this.f = f; } Foo getFoo(){ return f; } }
Constructor Summary | |
---|---|
Examples()
|
Method Summary | |
---|---|
boolean |
checkExpect(boolean a,
boolean b)
Check the given boolean against the Expected one |
boolean |
checkExpect(char a,
char b)
Check the given character against the Expected one |
boolean |
checkExpect(double a,
double b)
Check the given double-precision number against the Expected one |
boolean |
checkExpect(float a,
float b)
Check the given floating-point number against the Expected one |
boolean |
checkExpect(int a,
int b)
Check the given integer against the Expected one |
boolean |
checkExpect(long a,
long b)
Check the given long-integer against the Expected one |
boolean |
checkExpect(java.lang.Object a,
java.lang.Object b)
Check the given Object against the Expected one |
boolean |
checkExpect(short a,
short b)
Check the given short-integer against the Expected one |
boolean |
checkExpect(java.lang.String a,
java.lang.String b)
Check the given String against the Expected one |
boolean |
runTests()
Run all the tests and show all the instances for this Examples class |
boolean |
runTests(boolean show)
Run all the tests for this Examples class, tell whether or not the Example instances should be shown |
static void |
test()
Run all the tests for the invoking class, i.e., the outer Examples class, show all examples |
static void |
test(boolean show)
Run all the tests for the invoking class, i.e., the outer Examples class, passin whether or not to show all the examples |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Examples()
Method Detail |
---|
public static void test(boolean show)
public static void test()
public boolean runTests()
public boolean runTests(boolean show)
public boolean checkExpect(boolean a, boolean b)
public boolean checkExpect(char a, char b)
public boolean checkExpect(short a, short b)
public boolean checkExpect(int a, int b)
public boolean checkExpect(long a, long b)
public boolean checkExpect(float a, float b)
public boolean checkExpect(double a, double b)
public boolean checkExpect(java.lang.String a, java.lang.String b)
public boolean checkExpect(java.lang.Object a, java.lang.Object b)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |