de.uds.cs.st.dd.core.tester
Class JUnitTester

java.lang.Object
  |
  +--de.uds.cs.st.dd.core.tester.JUnitTester
All Implemented Interfaces:
Tester
Direct Known Subclasses:
JUnitFileTester

public class JUnitTester
extends Object
implements Tester

This tester is used for automatic JUnit testing. A JUnit-test is started in a separate thread. As soon as it is terminated, the test outcome will be returned. Note that the parameter c of the test function is not used (since all JUnit tests are executed without parameters).

Author:
Philipp Bouillon

Field Summary
private  int precision
          Precision of the test outcomes.
static int PRECISION_HIGH
          High precision: return DD.FAIL only if stack traces and messages * are identical.
static int PRECISION_LOW
          Low precision: whenever a JUnit test fails, return DD.FAIL.
static int PRECISION_NORMAL
          Normal precision: return DD.FAIL only if the current failing * stack trace equals the original failing stack trace (so, the * failure occurs at the same location), return DD.UNRESOLVED, * if the test fails at a different location.
private  int testCounter
          Counter that is increased each time, a test is executed (for debugging * purpose only).
protected  junit.framework.Test testObject
          The test object that runs the tests.
private  Throwable throwable
          Original exception trace of the failing test.
protected  long time
          Time the initial test has taken to complete its run.
private static int TIME_MULTIPLICATOR
          Determines the factor that is multiplied with the time to abort a test * case.
private static int TIME_OFFSET
          Determines the minimum time in milliseconds that has to pass until * a test is considered to be non-determinating.
 
Constructor Summary
JUnitTester()
          Creates a new JUnitTester object with no attached test object.
JUnitTester(junit.framework.Test testObject)
          Creates a new JUnitTester object and links it with the specified * test object.
 
Method Summary
private  int compareElements(StackTraceElement[] origElems, StackTraceElement[] currElems)
          Compares two StackTraceElement arrays as described in compareTraces.
private  int compareTraces(junit.framework.TestFailure fail)
          Compares two failure traces.
private  int determineTestOutcome(junit.framework.TestResult result)
          Determines the test outcome based on the precision.
 junit.framework.Test getTestObject()
           
 void setPrecision(int precision)
          Sets the test outcome precision.
 void setTestObject(junit.framework.Test testObject)
          Sets the current JUnit-test.
 void setThrowable(Throwable throwable)
          Sets the original failing exception.
 int test(TConfiguration c)
          Performs a JUnit test and returns the test outcome.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRECISION_LOW

public static final int PRECISION_LOW
Low precision: whenever a JUnit test fails, return DD.FAIL.

See Also:
Constant Field Values

PRECISION_NORMAL

public static final int PRECISION_NORMAL
Normal precision: return DD.FAIL only if the current failing * stack trace equals the original failing stack trace (so, the * failure occurs at the same location), return DD.UNRESOLVED, * if the test fails at a different location.

See Also:
Constant Field Values

PRECISION_HIGH

public static final int PRECISION_HIGH
High precision: return DD.FAIL only if stack traces and messages * are identical. DD.PASS if the test passed and DD.UNRESOLVED * otherwise.

See Also:
Constant Field Values

precision

private int precision
Precision of the test outcomes.


throwable

private Throwable throwable
Original exception trace of the failing test.


TIME_OFFSET

private static final int TIME_OFFSET
Determines the minimum time in milliseconds that has to pass until * a test is considered to be non-determinating. The time is actually * determined by adding this offset to the running time of the initial * test times TIME_MULTIPLICATOR. (TIME_OFFSET + initial_time) * * TIME_MULTIPLICATOR in milliseconds.

See Also:
Constant Field Values

TIME_MULTIPLICATOR

private static final int TIME_MULTIPLICATOR
Determines the factor that is multiplied with the time to abort a test * case.

See Also:
Constant Field Values

testObject

protected junit.framework.Test testObject
The test object that runs the tests.


time

protected long time
Time the initial test has taken to complete its run.


testCounter

private int testCounter
Counter that is increased each time, a test is executed (for debugging * purpose only).

Constructor Detail

JUnitTester

public JUnitTester()
Creates a new JUnitTester object with no attached test object. * Unless a test object is added later (via setTestObject), the * test method cannot be executed.


JUnitTester

public JUnitTester(junit.framework.Test testObject)
Creates a new JUnitTester object and links it with the specified * test object. * * @param testObject test object that runs the tests.

Method Detail

compareElements

private int compareElements(StackTraceElement[] origElems,
                            StackTraceElement[] currElems)
Compares two StackTraceElement arrays as described in compareTraces. * * @param origElems original failing stack trace. * @param currElems current failing stack trace. * @return DD.FAIL or DD.UNRESOLVED.


compareTraces

private int compareTraces(junit.framework.TestFailure fail)
Compares two failure traces. * If precision is normal, the traces must be equal up to (and including) * the first element that does not have the string "junit" in its name. * Usually this would be the line where the user called a assert* method. * If precision is high, the messages of the two traces must be equal, * too. * * @param fail Failure of the test. * @return DD.FAIL or DD.UNRESOLVED.


determineTestOutcome

private int determineTestOutcome(junit.framework.TestResult result)
Determines the test outcome based on the precision. This method is * only called if errors or failures occured in the JUnit test. The * question is now, if any failure in a JUnit test causes a result * of DD.FAIL, or if the outcome should rather be DD.UNRESOLVED if the * failure occured at a different position than before. * * @param result the result of the test. * @return int DD.FAIL or DD.UNRESOLVED.


test

public int test(TConfiguration c)
Performs a JUnit test and returns the test outcome. Note that * the parameter is not used here (since JUnit tests have no * parameters). If a JUnitFileTester is used, the test method will * modify the actual file that the JUnit test operates on. See * JUnitFileTester for details. * * @param c not used here. * @return int test outcome of the JUnit test. * @see dd.core.tester.JUnitFileTester

Specified by:
test in interface Tester

getTestObject

public junit.framework.Test getTestObject()
Returns:
Test the current JUnit-test.

setTestObject

public void setTestObject(junit.framework.Test testObject)
Sets the current JUnit-test.

Parameters:
testObject - JUnit-test to set.

setThrowable

public void setThrowable(Throwable throwable)
Sets the original failing exception. * * @param throwable failing exception.


setPrecision

public void setPrecision(int precision)
Sets the test outcome precision. * * @param precision new precision.