org.suiterunner
Class Suite

java.lang.Object
  |
  +--org.suiterunner.Suite
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Suite
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

A suite consisting of zero to many test methods and zero to many sub-Suites.

Signature of test methods in subclasses must be one of:

 public void testX();
 public void testX(Reporter v);
 
where X is some unique, hopefully meaningful, string.

Author:
Bill Venners
See Also:
Serialized Form

Constructor Summary
Suite()
          Construct a new Suite object with no sub-Suites.
Suite(java.util.List subSuites)
          Create a new Suite object with passed sub-Suites.
 
Method Summary
 void addSubSuite(Suite subSuite)
          Append the Suite passed as subSuite to the end of this Suite object's list of sub-Suites.
 void clearSubSuites()
          Clear this object's list of sub-Suites.
 void execute(Reporter reporter)
          Execute this suite object.
protected  void executeSubSuites(Reporter reporter)
          Execute zero to many of this suite object's sub-Suites.
protected  void executeTestMethods(Reporter reporter)
          Execute zero to many of this suite object's test methods.
static void fail()
          Throws TestFailedException to indicate a test failed.
static void fail(java.lang.String message)
          Throws TestFailedException, with the passed String message as the exception's detail message, to indicate a test failed.
static void fail(java.lang.String message, java.lang.Throwable cause)
          Throws TestFailedException, with the passed String message as the exception's detail message and Throwable cause, to indicate a test failed.
static void fail(java.lang.Throwable cause)
          Throws TestFailedException, with the passed Throwable cause, to indicate a test failed.
 java.util.List getSubSuites()
          Get an unmodifiable List of this Suite object's sub-Suites.
 java.lang.String getSuiteName()
          Get a user-friendly suite name for this Suite object.
 int getTestCount()
          Get the total number of tests that are expected to run when this suite object's execute method is invoked.
 java.lang.String getTestName(java.lang.String testMethodName)
          Get a user-friendly test name for this Suite object's test method, whose simple String name is passed as testMethodName.
static boolean isStopRequested()
          Gets the boolean stopRequested property.
static void setStopRequested(boolean stopRequested)
          Sets the stopRequested property to the specified boolean value.
 void setUpFixture()
          Setup the test fixture for this object's test methods.
 void tearDownFixture()
          Cleanup the test fixture for this object's test methods.
static void verify(boolean condition)
          Verify that a boolean condition is true.
static void verify(boolean condition, java.lang.String message)
          Verify that a boolean condition, described in String message, is true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Suite

public Suite()
Construct a new Suite object with no sub-Suites.

Suite

public Suite(java.util.List subSuites)
Create a new Suite object with passed sub-Suites. The suite name of this Suite object will be the fully qualified name of this object's class.
Parameters:
subSuites - A List of Suite objects. The specified List must be non-empty. Each element must be non-null and an instance of org.suiterunner.Suite.
Throws:
NullPointerException - if subSuites is null or any element of subSuites set is null.
java.lang.IllegalArgumentException - if subSuites is empty or if any non-null element of subSuites set is not an instance of org.suiterunner.Suite.
Method Detail

execute

public void execute(Reporter reporter)
Execute this suite object.

This class's implementation of this method calls these two methods on this object in this order:

  1. executeTestMethods(reporter)
  2. executeSubSuites(reporter)
Parameters:
reporter - the Reporter to which results will be reported
Throws:
NullPointerException - if reporter is null.

executeTestMethods

protected void executeTestMethods(Reporter reporter)
Execute zero to many of this suite object's test methods.

This class's implementation of this method uses reflection to discover all methods of the appropriate signature and invokes each one. The appropriate signature for test methods is:

Signature of test methods in subclasses must be one of:

 public void testX();
 public void testX(Reporter v);
 
where X is some unique, hopefully meaningful, string.
Parameters:
reporter - the Reporter to which results will be reported
Throws:
NullPointerException - if reporter is null.

executeSubSuites

protected void executeSubSuites(Reporter reporter)
Execute zero to many of this suite object's sub-Suites.

This class's implementation of this method invokes execute on each sub-Suite passed to this class's constructor or added via the addSubSuite method.

Parameters:
reporter - the Reporter to which results will be reported
Throws:
NullPointerException - if reporter is null.

getSuiteName

public java.lang.String getSuiteName()
Get a user-friendly suite name for this Suite object. This class's implementation of this method returns the simple name of this object's class. This class's implementation of executeSubSuites calls this method to obtain a name for Reports to pass to the suiteStarting, suiteCompleted, and suiteAborted methods of the Reporter.
Returns:
this Suite object's suite name.

getTestName

public java.lang.String getTestName(java.lang.String testMethodName)
Get a user-friendly test name for this Suite object's test method, whose simple String name is passed as testMethodName. This class's implementation of this method returns the concatenation of the simple name of this object's class, a dot, and the specified String testMethodName. This class's implementation of executeTestMethods calls this method to obtain a name for Reports to pass to the testStarting, testSucceeded, and testFailed methods of the Reporter.
Returns:
a test name for a test method of this Suite object.
Throws:
NullPointerException - if testMethodName is null

getTestCount

public int getTestCount()
Get the total number of tests that are expected to run when this suite object's execute method is invoked. This class's implementation of this method returns the sum of:

setUpFixture

public void setUpFixture()
Setup the test fixture for this object's test methods. This class's implementation of executeTestMethods invokes setUpFixture before invoking each test method.

tearDownFixture

public void tearDownFixture()
Cleanup the test fixture for this object's test methods. This class's implementation of executeTestMethods invokes tearDownFixture after each test method.

verify

public static void verify(boolean condition)
Verify that a boolean condition is true. If verification succeeds, returns normally. If verification fails, throws TestFailedException.
Parameters:
condition - the boolean condition to verify
Throws:
TestFailedException - if verification fails.

verify

public static void verify(boolean condition,
                          java.lang.String message)
Verify that a boolean condition, described in String message, is true. If verification succeeds, returns normally. If verification fails, throws TestFailedException with specified message as the exception's detail message.
Parameters:
condition - the boolean condition to verify
message - A message describing the failure.
Throws:
TestFailedException - if verification fails.
NullPointerException - if message is null.

fail

public static void fail()
Throws TestFailedException to indicate a test failed.

fail

public static void fail(java.lang.String message)
Throws TestFailedException, with the passed String message as the exception's detail message, to indicate a test failed.
Parameters:
message - A message describing the failure.
Throws:
NullPointerException - if message is null

fail

public static void fail(java.lang.String message,
                        java.lang.Throwable cause)
Throws TestFailedException, with the passed String message as the exception's detail message and Throwable cause, to indicate a test failed.
Parameters:
message - A message describing the failure.
cause - A Throwable that indicates the cause of the failure.
Throws:
NullPointerException - if message or cause is null

fail

public static void fail(java.lang.Throwable cause)
Throws TestFailedException, with the passed Throwable cause, to indicate a test failed. The getMessage method of the thrown TestFailedException will return cause.toString().
Parameters:
cause - A Throwable that indicates the cause of the failure.
Throws:
NullPointerException - if cause is null

addSubSuite

public void addSubSuite(Suite subSuite)
Append the Suite passed as subSuite to the end of this Suite object's list of sub-Suites.
Parameters:
subSuite - the sub-Suite to add
Throws:
NullPointerException - if subSuite is null.

getSubSuites

public java.util.List getSubSuites()
Get an unmodifiable List of this Suite object's sub-Suites.

clearSubSuites

public void clearSubSuites()
Clear this object's list of sub-Suites.

isStopRequested

public static boolean isStopRequested()
Gets the boolean stopRequested property. Call this method to determine whether a running test should stop. The execute method of any Suite, or code invoked by execute, should periodically check the stopRequested property. If true, the execute method should interrupt its work and simply return.

setStopRequested

public static void setStopRequested(boolean stopRequested)
Sets the stopRequested property to the specified boolean value. Call this method to request that a running test stop. The execute method of any Suite, or code invoked by execute, should periodically check the stopRequested property. If true, the execute method should interrupt its work and simply return.


Copyright (C) 2001-2003 Artima Software, Inc. All rights reserved.