J avolution v5.2 (J2SE 1.5+)

javolution.testing
Class TestSuite

java.lang.Object
  extended by javolution.testing.TestSuite
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ContextTestSuite, UtilTestSuite

public abstract class TestSuite
extends java.lang.Object
implements java.lang.Runnable

This class represents a collection of test cases and detailed information about the test being performed.

      class TextBuilderSuite extends TestSuite {
           public void run() {
                TestContext.info("Test Suite for TextBuilder");
                TestContext.test(appendInt);
                ...
           }
           TestCase appendInt = new TestCase() {
                TextBuilder tmp = new TextBuilder();
                int i;
                public void prepare() {
                   tmp.reset();
                   i = MathLib.randomInt(Integer.MIN_VALUE, Integer.MAX_VALUE);
                }
                public void execute() {
                    tmp.append(i);
                }
                public void validate() {
                    TextContext.assertEquals(String.valueOf(i), tmp.toString());
                    ... // We may also validate min, max, zero boundary cases here.
                }
                public CharSequence getDescription() {
                    return "TextBuilder.append(int)";
                }
           };
           ...
      }

Test suites can be run in the current logging context or within specialized test contexts:

 
         
      // Runs test suite directly (validation with results being logged).
      new TextBuilderSuite().run();
      
      // Performs regression (no logging but exception if test fails).
      TestContext.enter(TestContext.REGRESSION);
      try {
          new TextBuilderSuite().run();
      } finally {
          TestContext.exit();
      }
      
      // Performance measurements.
      TimeContext.enter(); 
      try {
          new TextBuilderSuite().run(); 
      } finally {
          TimeContext.exit();
      }

Nothing prevent a test suite to run other test suites. It is also possible to retrieve all the test cases which are to be executed by a test suite (for integration with an IDE for example).

Version:
5.2, August 19, 2007
Author:
Jean-Marie Dautelle
See Also:
Wikipedia: Test Suite

Constructor Summary
protected TestSuite()
          Default constructor.
 
Method Summary
 java.lang.CharSequence getDescription()
          Returns the description of this test suite or null if none.
 java.util.List getTestCases()
          Retrieves the list of test cases to be executed by this test suite.
abstract  void run()
          Runs this test suite.
 java.lang.String toString()
          Returns the String representation of this test suite (the description or the class name by default).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TestSuite

protected TestSuite()
Default constructor.

Method Detail

run

public abstract void run()
Runs this test suite.

Specified by:
run in interface java.lang.Runnable

getTestCases

public java.util.List getTestCases()
Retrieves the list of test cases to be executed by this test suite.

Returns:
the ordered list of test cases.

getDescription

public java.lang.CharSequence getDescription()
Returns the description of this test suite or null if none.

Returns:
the description or null

toString

public java.lang.String toString()
Returns the String representation of this test suite (the description or the class name by default).

Overrides:
toString in class java.lang.Object
Returns:
the string representation of this test suite.

J avolution v5.2 (J2SE 1.5+)

Copyright © 2005 - 2007 Javolution.