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 don't have a finalizer method in the formatters "lifecycle", we register this formatter as BuildListener and generate the new java source on taskFinished event.
Modifier and Type | Class and Description |
---|---|
static class |
FailureRecorder.TestInfos
TestInfos holds information about a given test for later use.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_CLASS_LOCATION
Default location and name for the generated JUnit class file,
in the temp directory + FailedTests
|
static java.lang.String |
MAGIC_PROPERTY_CLASS_LOCATION
This is the name of a magic System property ("ant.junit.failureCollector").
|
description, location, project
Constructor and Description |
---|
FailureRecorder() |
Modifier and Type | Method and Description |
---|---|
void |
addError(junit.framework.Test test,
java.lang.Throwable throwable)
Add the failed test to the list.
|
void |
addFailure(junit.framework.Test test,
junit.framework.AssertionFailedError error)
Add the failed test to the list.
|
void |
buildFinished(BuildEvent event)
Not used
Signals that the last target has finished.
|
void |
buildStarted(BuildEvent event)
Not used
Signals that a build has started.
|
void |
endTest(junit.framework.Test test)
Not used
|
void |
endTestSuite(JUnitTest suite)
Not used
The whole testsuite ended.
|
void |
log(java.lang.String message)
Logging facade in INFO-mode.
|
void |
messageLogged(BuildEvent event)
Not used
Signals a message logging event.
|
void |
setOutput(java.io.OutputStream out)
Not used
Sets the stream the formatter is supposed to write its results to.
|
void |
setProject(Project project)
This method is called by the Ant runtime by reflection.
|
void |
setSystemError(java.lang.String err)
Not used
This is what the test has written to System.err
|
void |
setSystemOutput(java.lang.String out)
Not used
This is what the test has written to System.out
|
void |
startTest(junit.framework.Test test)
Not used
|
void |
startTestSuite(JUnitTest suite)
Not used
The whole testsuite started.
|
void |
targetFinished(BuildEvent event)
Not used
Signals that a target has finished.
|
void |
targetStarted(BuildEvent event)
Not used
Signals that a target is starting.
|
void |
taskFinished(BuildEvent event)
The task outside of this JUnitResultFormatter is the <junit> task.
|
void |
taskStarted(BuildEvent event)
Not used
Signals that a task is starting.
|
void |
verbose(java.lang.String message)
Logging facade in VERBOSE-mode.
|
clone, getDescription, getLocation, getProject, log, setDescription, setLocation
public static final java.lang.String MAGIC_PROPERTY_CLASS_LOCATION
DEFAULT_CLASS_LOCATION
,
Constant Field Valuespublic static final java.lang.String DEFAULT_CLASS_LOCATION
public void setProject(Project project)
setProject
in class ProjectComponent
project
- project referencepublic void endTestSuite(JUnitTest suite) throws BuildException
endTestSuite
in interface JUnitResultFormatter
suite
- the suite.BuildException
- on error.public void addError(junit.framework.Test test, java.lang.Throwable throwable)
addError
in interface junit.framework.TestListener
test
- the test that erred.throwable
- the reason it erred.TestListener.addError(junit.framework.Test, java.lang.Throwable)
public void addFailure(junit.framework.Test test, junit.framework.AssertionFailedError error)
addFailure
in interface junit.framework.TestListener
test
- the test that failed.error
- the assertion that failed.TestListener.addFailure(junit.framework.Test, junit.framework.AssertionFailedError)
public void setOutput(java.io.OutputStream out)
setOutput
in interface JUnitResultFormatter
setOutput
in interface JUnitTaskMirror.JUnitResultFormatterMirror
out
- the output stream to use.public void setSystemError(java.lang.String err)
setSystemError
in interface JUnitResultFormatter
err
- the string to write.public void setSystemOutput(java.lang.String out)
setSystemOutput
in interface JUnitResultFormatter
out
- the string to write.public void startTestSuite(JUnitTest suite) throws BuildException
startTestSuite
in interface JUnitResultFormatter
suite
- the suite.BuildException
- on error.public void endTest(junit.framework.Test test)
endTest
in interface junit.framework.TestListener
public void startTest(junit.framework.Test test)
startTest
in interface junit.framework.TestListener
public void log(java.lang.String message)
log
in class ProjectComponent
message
- Log-messagepublic void verbose(java.lang.String message)
message
- Log-messagepublic void buildFinished(BuildEvent event)
buildFinished
in interface BuildListener
event
- An event with any relevant extra information.
Must not be null
.BuildEvent.getException()
public void buildStarted(BuildEvent event)
This event is fired before the project instance is fully configured. In particular no properties have been set and the project may not know its name or default target, yet.
buildStarted
in interface BuildListener
event
- An event with any relevant extra information.
Must not be null
.public void messageLogged(BuildEvent event)
messageLogged
in interface BuildListener
event
- An event with any relevant extra information.
Must not be null
.BuildEvent.getMessage()
,
BuildEvent.getException()
,
BuildEvent.getPriority()
public void targetFinished(BuildEvent event)
targetFinished
in interface BuildListener
event
- An event with any relevant extra information.
Must not be null
.BuildEvent.getException()
public void targetStarted(BuildEvent event)
targetStarted
in interface BuildListener
event
- An event with any relevant extra information.
Must not be null
.BuildEvent.getTarget()
public void taskFinished(BuildEvent event)
taskFinished
in interface BuildListener
event
- not usedBuildListener.taskFinished(org.apache.tools.ant.BuildEvent)
public void taskStarted(BuildEvent event)
taskStarted
in interface BuildListener
event
- An event with any relevant extra information.
Must not be null
.BuildEvent.getTask()