testing
Class Examples

java.lang.Object
  extended by testing.Examples
Direct Known Subclasses:
FooExamples

public class Examples
extends java.lang.Object

The parent of Example/Test classes.

Use of the Examples Class

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

Examples

public Examples()
Method Detail

test

public 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


test

public static void test()
Run all the tests for the invoking class, i.e., the outer Examples class, show all examples


runTests

public boolean runTests()
Run all the tests and show all the instances for this Examples class


runTests

public boolean runTests(boolean show)
Run all the tests for this Examples class, tell whether or not the Example instances should be shown


checkExpect

public boolean checkExpect(boolean a,
                           boolean b)
Check the given boolean against the Expected one


checkExpect

public boolean checkExpect(char a,
                           char b)
Check the given character against the Expected one


checkExpect

public boolean checkExpect(short a,
                           short b)
Check the given short-integer against the Expected one


checkExpect

public boolean checkExpect(int a,
                           int b)
Check the given integer against the Expected one


checkExpect

public boolean checkExpect(long a,
                           long b)
Check the given long-integer against the Expected one


checkExpect

public boolean checkExpect(float a,
                           float b)
Check the given floating-point number against the Expected one


checkExpect

public boolean checkExpect(double a,
                           double b)
Check the given double-precision number against the Expected one


checkExpect

public boolean checkExpect(java.lang.String a,
                           java.lang.String b)
Check the given String against the Expected one


checkExpect

public boolean checkExpect(java.lang.Object a,
                           java.lang.Object b)
Check the given Object against the Expected one