consciouscode.seedling.junit
Class TestRunnerNode

java.lang.Object
  extended by consciouscode.seedling.tree.GenericNode
      extended by consciouscode.seedling.junit.TestRunnerNode
All Implemented Interfaces:
LocatableNode, ServiceNode

public class TestRunnerNode
extends GenericNode
implements ServiceNode

A seedling node that runs tests from "within" the seedling.

The node must have its testCase property configured with the name of the desired TestCase class. The test suite can then be run by calling runTestCase() or runTestCaseAndMaybeExit().

When a TestRunnerNode is started (via startService()), the test suite is started in a new thread. If the exitAfterTests property is true (the default), the JVM exits after the tests complete with an exit status indicating success (zero) or failure (one).


Field Summary
protected static String EXCEPTION_RUNNING_TEST_CASE_MSG
           
 
Constructor Summary
TestRunnerNode()
           
 
Method Summary
 junit.framework.TestResult getLastResult()
          Gets the TestResult generated by the previous test run.
protected  Runnable makeRunnable()
          Create a Runnable that will run the test suite.
protected  void runInAppropriateThread(Runnable testingRunnable)
          Subclasses can override this to change the thread in which the tests are run.
 junit.framework.TestResult runTestCase()
          Run the test case in the active thread.
 void runTestCaseAndMaybeExit()
          Run the test case in the active thread, and then exit the JVM if the exitAfterTests property is true.
 void setExitAfterTests(boolean exit)
          Indicate whether this TestRunner should exit the JVM after running the tests.
 void setTestCase(String testCase)
          Specify the classname of the TestCase to run.
 void startService()
          Run the test case.
 void stopService()
          Stops a Seedling service.
 junit.framework.TestResult waitForResult()
           
 
Methods inherited from class consciouscode.seedling.tree.GenericNode
getLocalRoot, getLog, getNodeLocation, getNodeName, getParentBranch, isLoggingDebug, nodeInstalled, setLog, setLoggingDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXCEPTION_RUNNING_TEST_CASE_MSG

protected static final String EXCEPTION_RUNNING_TEST_CASE_MSG
See Also:
Constant Field Values
Constructor Detail

TestRunnerNode

public TestRunnerNode()
Method Detail

setTestCase

public void setTestCase(String testCase)
Specify the classname of the TestCase to run. This property has no default value.


setExitAfterTests

public void setExitAfterTests(boolean exit)
Indicate whether this TestRunner should exit the JVM after running the tests. This property is true by default.


getLastResult

public junit.framework.TestResult getLastResult()
Gets the TestResult generated by the previous test run. If the tests are currently running in another thread, this method will wait for them to complete before returning.

Returns:
null if the the tests haven't run to completion.

waitForResult

public junit.framework.TestResult waitForResult()
                                         throws InterruptedException
Throws:
InterruptedException

runTestCase

public junit.framework.TestResult runTestCase()
                                       throws Exception
Run the test case in the active thread. Before calling this method, the test case class must be specified by name via the testCase property.

Returns:
the JUnit TestResult object containing the test details.
Throws:
Exception - if the test case could not be found.

runTestCaseAndMaybeExit

public void runTestCaseAndMaybeExit()
Run the test case in the active thread, and then exit the JVM if the exitAfterTests property is true. To exit, this method calls System.exit(int) with an exit code of either zero (if all tests ran successfully) or one (if any test failed).

Before calling this method, the test case class must be specified by name via the testCase property.


startService

public void startService()
Run the test case. This implementation runs the tests in a new thread, then exits the JVM if the exitAfterTests property is true.

Specified by:
startService in interface ServiceNode

stopService

public void stopService()
Description copied from interface: ServiceNode
Stops a Seedling service. This is called by the Seedling runtime as the node is uninstalled, either explicitly or by the Seedling itself being stopped.

Implementations of this method must not do anything that may change the state of the parent Seedling. In particular, it cannot call any overload of the following methods: BranchNode.getNode(java.lang.String), BranchNode.getChild(java.lang.String), GrowingBranch.installChild(java.lang.String, java.lang.Object), GrowingBranch.uninstallChild(java.lang.String).

Furthermore, this method may be called from within a JVM shutdown hook, which implies that it must work promptly and carefully.

Specified by:
stopService in interface ServiceNode
See Also:
Runtime.addShutdownHook(java.lang.Thread)

makeRunnable

protected Runnable makeRunnable()
Create a Runnable that will run the test suite. This implementation creates a Runnable that simply calls runTestCaseAndMaybeExit(). Subclasses may override this method to implement different behavior.


runInAppropriateThread

protected void runInAppropriateThread(Runnable testingRunnable)
Subclasses can override this to change the thread in which the tests are run. This implementation runs the tests in a new thread.



Copyright © 2001–2012 Todd V. Jonker. All Rights Reserved.