org.apache.tools.ant.taskdefs.optional.junit

Class FailureRecorder

public class FailureRecorder extends ProjectComponent implements JUnitResultFormatter, BuildListener

Collects all failing test cases and creates a new JUnit test class containing a suite() method which calls these failed tests.

Having classes A ... D with each several testcases you could earn a new test class like

 // generated on: 2007.08.06 09:42:34,555
 import junit.framework.*;
 public class FailedTests extends TestCase {
     public FailedTests(String testname) {
         super(testname);
     }
     public static Test suite() {
         TestSuite suite = new TestSuite();
         suite.addTest( new B("test04") );
         suite.addTest( new org.D("test10") );
         return suite;
     }
 }
 
Because each running test case gets its own formatter, we collect the failing test cases in a static list. Because we dont have a finalizer method in the formatters "lifecycle", we register this formatter as BuildListener and generate the new java source on taskFinished event.

Since: Ant 1.8.0

Nested Class Summary
static classFailureRecorder.TestInfos
TestInfos holds information about a given test for later use.
Field Summary
static StringDEFAULT_CLASS_LOCATION
Default location and name for the generated JUnit class file, in the temp directory + FailedTests
static StringMAGIC_PROPERTY_CLASS_LOCATION
This is the name of a magic System property ({@value }).
Method Summary
voidaddError(Test test, Throwable throwable)
Add the failed test to the list.
voidaddFailure(Test test, AssertionFailedError error)
Add the failed test to the list.
voidbuildFinished(BuildEvent event)
Not used
voidbuildStarted(BuildEvent event)
Not used
voidendTest(Test test)
Not used
voidendTestSuite(JUnitTest suite)
Not used
voidlog(String message)
Logging facade in INFO-mode.
voidmessageLogged(BuildEvent event)
Not used
voidsetOutput(OutputStream out)
Not used
voidsetProject(Project project)
This method is called by the Ant runtime by reflection.
voidsetSystemError(String err)
Not used
voidsetSystemOutput(String out)
Not used
voidstartTest(Test test)
Not used
voidstartTestSuite(JUnitTest suite)
Not used
voidtargetFinished(BuildEvent event)
Not used
voidtargetStarted(BuildEvent event)
Not used
voidtaskFinished(BuildEvent event)
The task outside of this JUnitResultFormatter is the task.
voidtaskStarted(BuildEvent event)
Not used
voidverbose(String message)
Logging facade in VERBOSE-mode.

Field Detail

DEFAULT_CLASS_LOCATION

public static final String DEFAULT_CLASS_LOCATION
Default location and name for the generated JUnit class file, in the temp directory + FailedTests

MAGIC_PROPERTY_CLASS_LOCATION

public static final String MAGIC_PROPERTY_CLASS_LOCATION
This is the name of a magic System property ({@value }). The value of this System property should point to the location where to store the generated class (without suffix). Default location and name is defined in DEFAULT_CLASS_LOCATION.

See Also: DEFAULT_CLASS_LOCATION

Method Detail

addError

public void addError(Test test, Throwable throwable)
Add the failed test to the list.

Parameters: test the test that errored. throwable the reason it errored.

See Also: junit.framework.TestListener#addError(junit.framework.Test, java.lang.Throwable)

addFailure

public void addFailure(Test test, AssertionFailedError error)
Add the failed test to the list.

Parameters: test the test that failed. error the assertion that failed.

See Also: junit.framework.TestListener#addFailure(junit.framework.Test, junit.framework.AssertionFailedError)

buildFinished

public void buildFinished(BuildEvent event)
Not used {@inheritDoc }

buildStarted

public void buildStarted(BuildEvent event)
Not used {@inheritDoc }

endTest

public void endTest(Test test)
Not used {@inheritDoc }

endTestSuite

public void endTestSuite(JUnitTest suite)
Not used {@inheritDoc }

log

public void log(String message)
Logging facade in INFO-mode.

Parameters: message Log-message

messageLogged

public void messageLogged(BuildEvent event)
Not used {@inheritDoc }

setOutput

public void setOutput(OutputStream out)
Not used {@inheritDoc }

setProject

public void setProject(Project project)
This method is called by the Ant runtime by reflection. We use the project reference for registration of this class as BuildListener.

Parameters: project project reference

setSystemError

public void setSystemError(String err)
Not used {@inheritDoc }

setSystemOutput

public void setSystemOutput(String out)
Not used {@inheritDoc }

startTest

public void startTest(Test test)
Not used {@inheritDoc }

startTestSuite

public void startTestSuite(JUnitTest suite)
Not used {@inheritDoc }

targetFinished

public void targetFinished(BuildEvent event)
Not used {@inheritDoc }

targetStarted

public void targetStarted(BuildEvent event)
Not used {@inheritDoc }

taskFinished

public void taskFinished(BuildEvent event)
The task outside of this JUnitResultFormatter is the task. So all tests passed and we could create the new java class.

Parameters: event not used

See Also: taskFinished

taskStarted

public void taskStarted(BuildEvent event)
Not used {@inheritDoc }

verbose

public void verbose(String message)
Logging facade in VERBOSE-mode.

Parameters: message Log-message