de.uds.cs.st.dd.core
Class JUnitRunner

java.lang.Object
  |
  +--junit.runner.BaseTestRunner
        |
        +--de.uds.cs.st.dd.core.JUnitRunner
All Implemented Interfaces:
ISimpleViewer, junit.framework.TestListener

public class JUnitRunner
extends junit.runner.BaseTestRunner
implements ISimpleViewer

The JUnitRunner is used to launch a JUnit configuration automatically.

Author:
Philipp Bouillon

Field Summary
private  Socket clientSocket
          The client socket.
private  int deltaDebuggingMode
          Mode of the Delta Debugging algorithm.
private  String host
          Host to connect to, default is the localhost
private  String inputFile
          Name of the input file of the JUnit test that is to be analyzed with.
static String MSG_FAILING_INPUT
          Constant message header indicating the failing input.
static String MSG_FAILING_INPUT_ENDED
          Constant message header indicating the end of the failing * input message.
static String MSG_JUNIT_ENDED
          Constant message header indicating the end of a JUnit run.
static String MSG_MINIMIZE_ENDED
          Constant message header indicating the end of a Delta Debugging * result message.
static String MSG_MINIMIZE_RESULT
          Constant message header indicating the result of a Delta Debugging * process (i.e.
static String MSG_PASSING_INPUT
          Constant message header indicating the passing input.
static String MSG_PASSING_INPUT_ENDED
          Constant message header indicating the end of the passing * input message.
static String MSG_STATUS_MINIMIZED
          Constant message header indicating the finished status of a Delta * Debugging analysis.
static String MSG_STATUS_TEMPORARY
          Constant message header indicating a temporary result of a Delta * Debugging analysis.
static String MSG_TEST_ENDED
          Constant message header indicating the end of a test.
static String MSG_TEST_FAILED
          Constant message header indicating the failure of a test.
static String MSG_TEST_FAILED_ENDED
          Constant message header indicating the end of a test-failure message.
static String MSG_TEST_RUN_STARTED
          Constant message header indicating the beginning of a test run.
static String MSG_TEXT
          Constant message header indicating a text message.
static String MSG_TEXT_ENDED
          Constant message header indicating the end of a text message.
private  String originalFileName
          Name of the original file.
private  int port
          Port to connect to.
private  junit.framework.TestResult result
          Holds information on the test result.
private  boolean storeFailingTests
          A flag to indicate, if failing tests are to be stored or not.
private  PrintWriter writer
          Print writer for sending messages
 
Fields inherited from class junit.runner.BaseTestRunner
SUITE_METHODNAME
 
Constructor Summary
JUnitRunner()
          Creates a new JUnitRunner and allocates the test result.
 
Method Summary
private  boolean connect()
          Connects to remote listeners.
protected  junit.framework.TestResult createTestResult()
          Convenience method to create a new TestResult object.
 junit.framework.TestResult doRun(junit.framework.Test test)
          Runs the specified test(s).
 void endTest(junit.framework.Test test)
           
private  junit.framework.Test findTest(String suiteClassName, String methodName)
          Helper method to find a Test class based on the name of the test suite * and a method name.
 int getLineNumber(Throwable exc, String text)
          Determines the line number of the failure as it occured in the * specified test function (i.e.
 junit.runner.TestSuiteLoader getLoader()
          Returns the standard suite loader.
static void main(String[] args)
          Main entry point of the JUnitRunner.
static void run(Class testClass)
          Runs the specified test class.
static junit.framework.TestResult run(junit.framework.Test test)
          Runs a single test.
protected  void runFailed(String arg0)
           
 void sendMessage(String msg)
          Used to send an arbitrary message.
 void sendTextMessage(String message)
          Convenience method to send a text message.
 void shutDown()
          Cleanup.
 junit.framework.TestResult start(String[] args)
          Actually starts the testing with the command line parameters that * have been specified when calling the main function.
 void startTest(junit.framework.Test test)
           
 void testEnded(String test)
           
 void testFailed(int status, junit.framework.Test test, Throwable exc)
          Overrides the testFailed method from the BaseTestRunner class.
 void testStarted(String test)
           
 
Methods inherited from class junit.runner.BaseTestRunner
addError, addFailure, clearStatus, elapsedTimeAsString, extractClassName, getFilteredTrace, getFilteredTrace, getPreference, getPreference, getPreferences, getTest, inVAJava, loadSuiteClass, processArguments, savePreferences, setLoading, setPreference, setPreferences, showStackRaw, truncate, useReloadingTestSuiteLoader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MSG_TEST_ENDED

public static final String MSG_TEST_ENDED
Constant message header indicating the end of a test.

See Also:
Constant Field Values

MSG_MINIMIZE_RESULT

public static final String MSG_MINIMIZE_RESULT
Constant message header indicating the result of a Delta Debugging * process (i.e. minimization or isolation).

See Also:
Constant Field Values

MSG_MINIMIZE_ENDED

public static final String MSG_MINIMIZE_ENDED
Constant message header indicating the end of a Delta Debugging * result message.

See Also:
Constant Field Values

MSG_FAILING_INPUT

public static final String MSG_FAILING_INPUT
Constant message header indicating the failing input.

See Also:
Constant Field Values

MSG_FAILING_INPUT_ENDED

public static final String MSG_FAILING_INPUT_ENDED
Constant message header indicating the end of the failing * input message. * TODO this won't work, if the input contains the String "FailingEnded". * instead of writing two messages to indicate begin and end, send just * one message that includes the length of the following message.

See Also:
Constant Field Values

MSG_PASSING_INPUT

public static final String MSG_PASSING_INPUT
Constant message header indicating the passing input.

See Also:
Constant Field Values

MSG_PASSING_INPUT_ENDED

public static final String MSG_PASSING_INPUT_ENDED
Constant message header indicating the end of the passing * input message. * TODO this won't work, if the input contains the String "PassingEnded". * instead of writing two messages to indicate begin and end, send just * one message that includes the length of the following message.

See Also:
Constant Field Values

MSG_TEST_FAILED

public static final String MSG_TEST_FAILED
Constant message header indicating the failure of a test.

See Also:
Constant Field Values

MSG_TEST_FAILED_ENDED

public static final String MSG_TEST_FAILED_ENDED
Constant message header indicating the end of a test-failure message.

See Also:
Constant Field Values

MSG_TEST_RUN_STARTED

public static final String MSG_TEST_RUN_STARTED
Constant message header indicating the beginning of a test run.

See Also:
Constant Field Values

MSG_JUNIT_ENDED

public static final String MSG_JUNIT_ENDED
Constant message header indicating the end of a JUnit run.

See Also:
Constant Field Values

MSG_TEXT

public static final String MSG_TEXT
Constant message header indicating a text message.

See Also:
Constant Field Values

MSG_TEXT_ENDED

public static final String MSG_TEXT_ENDED
Constant message header indicating the end of a text message.

See Also:
Constant Field Values

MSG_STATUS_MINIMIZED

public static final String MSG_STATUS_MINIMIZED
Constant message header indicating the finished status of a Delta * Debugging analysis.

See Also:
Constant Field Values

MSG_STATUS_TEMPORARY

public static final String MSG_STATUS_TEMPORARY
Constant message header indicating a temporary result of a Delta * Debugging analysis.

See Also:
Constant Field Values

clientSocket

private Socket clientSocket
The client socket.


writer

private PrintWriter writer
Print writer for sending messages


host

private String host
Host to connect to, default is the localhost


port

private int port
Port to connect to.


deltaDebuggingMode

private int deltaDebuggingMode
Mode of the Delta Debugging algorithm. Either MINIMIZATION or ISOLATION.


inputFile

private String inputFile
Name of the input file of the JUnit test that is to be analyzed with. * Delta Debugging. Will only be set, if the runner is called with the -m * command line option to indicate that file analysis should occur. Usually, * this is a temporary copy of the original file.


originalFileName

private String originalFileName
Name of the original file.


result

private junit.framework.TestResult result
Holds information on the test result.


storeFailingTests

private boolean storeFailingTests
A flag to indicate, if failing tests are to be stored or not. If set * to true, the JUnitRunner sends the names of all failing tests to the * connected writer.

Constructor Detail

JUnitRunner

public JUnitRunner()
Creates a new JUnitRunner and allocates the test result.

Method Detail

run

public static void run(Class testClass)
Runs the specified test class.

Parameters:
testClass - class which holds the tests to be executed.

run

public static junit.framework.TestResult run(junit.framework.Test test)
Runs a single test.

Parameters:
test - test to be run.
Returns:
TestResult outcome of the test.

getLoader

public junit.runner.TestSuiteLoader getLoader()
Returns the standard suite loader.

Overrides:
getLoader in class junit.runner.BaseTestRunner
Returns:
a new object of StandardTestSuiteLoader.

testStarted

public void testStarted(String test)
Specified by:
testStarted in class junit.runner.BaseTestRunner

testEnded

public void testEnded(String test)
Specified by:
testEnded in class junit.runner.BaseTestRunner

startTest

public void startTest(junit.framework.Test test)
Specified by:
startTest in interface junit.framework.TestListener
Overrides:
startTest in class junit.runner.BaseTestRunner

endTest

public void endTest(junit.framework.Test test)
Specified by:
endTest in interface junit.framework.TestListener
Overrides:
endTest in class junit.runner.BaseTestRunner

getLineNumber

public int getLineNumber(Throwable exc,
                         String text)
Determines the line number of the failure as it occured in the * specified test function (i.e. the line where the assert* statement * failed). * * @param exc Throwable object that has been thrown by the test. * @param text name of the test method. * @return int the line number where the assertion failed or -1 if the * failure did not occur in the specified function.


testFailed

public void testFailed(int status,
                       junit.framework.Test test,
                       Throwable exc)
Overrides the testFailed method from the BaseTestRunner class. * Depending on the command line arguments, this function does one of * two things: either, it sends the name of the failing test method * and the line, where the error occured to the writer, or * it applied Delta Debugging to the input file of that test. * * @param status status of the test (not used). * @param test the failed test object. * @param exc the exception trace of the failure.

Specified by:
testFailed in class junit.runner.BaseTestRunner

runFailed

protected void runFailed(String arg0)
Specified by:
runFailed in class junit.runner.BaseTestRunner
See Also:
BaseTestRunner.runFailed(java.lang.String)

createTestResult

protected junit.framework.TestResult createTestResult()
Convenience method to create a new TestResult object. * * @return TestResult a newly created TestResult object.


doRun

public junit.framework.TestResult doRun(junit.framework.Test test)
Runs the specified test(s). * * @param test Test object that performs the test(s). * @return TestResult the result of the test(s).


main

public static void main(String[] args)
Main entry point of the JUnitRunner. * Command line options are: * -f filename: stores all failing test names and the exact * line of the assertion violation in the specified file. * * _OR_ * * -m inputfilename testname: minimizes the specified file, if * a failure is detected in the test named testname. * * Do not specifiy both arguments. * * Additionaly, you have to specify the name of the class that holds * the test. * * Example: JUnitRunner -m input.txt testMultiply mymath.ArithmeticTester * * @param args Command line parameters (see above).


findTest

private junit.framework.Test findTest(String suiteClassName,
                                      String methodName)
Helper method to find a Test class based on the name of the test suite * and a method name. * * @param suiteClassName name of the test suite. * @param methodName name of the test method. * @return the test object that matches the criteria or null, if none was * found.


sendMessage

public void sendMessage(String msg)
Description copied from interface: ISimpleViewer
Used to send an arbitrary message. Substrings may be interpreted or left alone.

Specified by:
sendMessage in interface ISimpleViewer
Parameters:
msg - the message to be sent. May contain additional information about the message type.

sendTextMessage

public void sendTextMessage(String message)
Description copied from interface: ISimpleViewer
Convenience method to send a text message.

Specified by:
sendTextMessage in interface ISimpleViewer
Parameters:
message - text message to send.

shutDown

public void shutDown()
Cleanup.


connect

private boolean connect()
Connects to remote listeners. * * @return true if the connection could be established, false otherwise.


start

public junit.framework.TestResult start(String[] args)
                                 throws Exception
Actually starts the testing with the command line parameters that * have been specified when calling the main function. * * @param args Command line parameters (see main). * @return result of the test. * @throws Exception if no test cases were specified or the test cases * could not be found.

Exception