Class FailureRecorder
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.taskdefs.optional.junit.FailureRecorder
- All Implemented Interfaces:
- Cloneable,- EventListener,- junit.framework.TestListener,- BuildListener,- JUnitResultFormatter,- JUnitTaskMirror.JUnitResultFormatterMirror
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.- Since:
- Ant 1.8.0
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classTestInfos holds information about a given test for later use.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringDefault location and name for the generated JUnit class file, in the temp directory + FailedTestsstatic final StringThis is the name of a magic System property ("ant.junit.failureCollector").Fields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdd the failed test to the list.voidaddFailure(junit.framework.Test test, junit.framework.AssertionFailedError error) Add the failed test to the list.voidbuildFinished(BuildEvent event) Not used Signals that the last target has finished.voidbuildStarted(BuildEvent event) Not used Signals that a build has started.voidendTest(junit.framework.Test test) Not usedvoidendTestSuite(JUnitTest suite) Not used The whole testsuite ended.voidLogging facade in INFO-mode.voidmessageLogged(BuildEvent event) Not used Signals a message logging event.voidsetOutput(OutputStream out) Not used Sets the stream the formatter is supposed to write its results to.voidsetProject(Project project) This method is called by the Ant runtime by reflection.voidsetSystemError(String err) Not used This is what the test has written to System.errvoidsetSystemOutput(String out) Not used This is what the test has written to System.outvoidstartTest(junit.framework.Test test) Not usedvoidstartTestSuite(JUnitTest suite) Not used The whole testsuite started.voidtargetFinished(BuildEvent event) Not used Signals that a target has finished.voidtargetStarted(BuildEvent event) Not used Signals that a target is starting.voidtaskFinished(BuildEvent event) The task outside of this JUnitResultFormatter is the <junit> task.voidtaskStarted(BuildEvent event) Not used Signals that a task is starting.voidLogging facade in VERBOSE-mode.Methods inherited from class org.apache.tools.ant.ProjectComponentclone, getDescription, getLocation, getProject, log, setDescription, setLocation
- 
Field Details- 
MAGIC_PROPERTY_CLASS_LOCATIONThis is the name of a magic System property ("ant.junit.failureCollector"). 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_LOCATIONDefault location and name for the generated JUnit class file, in the temp directory + FailedTests
 
- 
- 
Constructor Details- 
FailureRecorderpublic FailureRecorder()
 
- 
- 
Method Details- 
setProjectThis method is called by the Ant runtime by reflection. We use the project reference for registration of this class as BuildListener.- Overrides:
- setProjectin class- ProjectComponent
- Parameters:
- project- project reference
 
- 
endTestSuiteNot used The whole testsuite ended.- Specified by:
- endTestSuitein interface- JUnitResultFormatter
- Parameters:
- suite- the suite.
- Throws:
- BuildException- on error.
 
- 
addErrorAdd the failed test to the list.- Specified by:
- addErrorin interface- junit.framework.TestListener
- Parameters:
- test- the test that erred.
- throwable- the reason it erred.
- See Also:
 
- 
addFailurepublic void addFailure(junit.framework.Test test, junit.framework.AssertionFailedError error) Add the failed test to the list.- Specified by:
- addFailurein interface- junit.framework.TestListener
- Parameters:
- test- the test that failed.
- error- the assertion that failed.
- See Also:
 
- 
setOutputNot used Sets the stream the formatter is supposed to write its results to.- Specified by:
- setOutputin interface- JUnitResultFormatter
- Specified by:
- setOutputin interface- JUnitTaskMirror.JUnitResultFormatterMirror
- Parameters:
- out- the output stream to use.
 
- 
setSystemErrorNot used This is what the test has written to System.err- Specified by:
- setSystemErrorin interface- JUnitResultFormatter
- Parameters:
- err- the string to write.
 
- 
setSystemOutputNot used This is what the test has written to System.out- Specified by:
- setSystemOutputin interface- JUnitResultFormatter
- Parameters:
- out- the string to write.
 
- 
startTestSuiteNot used The whole testsuite started.- Specified by:
- startTestSuitein interface- JUnitResultFormatter
- Parameters:
- suite- the suite.
- Throws:
- BuildException- on error.
 
- 
endTestpublic void endTest(junit.framework.Test test) Not used- Specified by:
- endTestin interface- junit.framework.TestListener
 
- 
startTestpublic void startTest(junit.framework.Test test) Not used- Specified by:
- startTestin interface- junit.framework.TestListener
 
- 
logLogging facade in INFO-mode.- Overrides:
- login class- ProjectComponent
- Parameters:
- message- Log-message
 
- 
verboseLogging facade in VERBOSE-mode.- Parameters:
- message- Log-message
 
- 
buildFinishedNot used Signals that the last target has finished. This event will still be fired if an error occurred during the build.- Specified by:
- buildFinishedin interface- BuildListener
- Parameters:
- event- An event with any relevant extra information. Must not be- null.
- See Also:
 
- 
buildStartedNot used Signals that a build has started. This event is fired before any targets have started.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. - Specified by:
- buildStartedin interface- BuildListener
- Parameters:
- event- An event with any relevant extra information. Must not be- null.
 
- 
messageLoggedNot used Signals a message logging event.- Specified by:
- messageLoggedin interface- BuildListener
- Parameters:
- event- An event with any relevant extra information. Must not be- null.
- See Also:
 
- 
targetFinishedNot used Signals that a target has finished. This event will still be fired if an error occurred during the build.- Specified by:
- targetFinishedin interface- BuildListener
- Parameters:
- event- An event with any relevant extra information. Must not be- null.
- See Also:
 
- 
targetStartedNot used Signals that a target is starting.- Specified by:
- targetStartedin interface- BuildListener
- Parameters:
- event- An event with any relevant extra information. Must not be- null.
- See Also:
 
- 
taskFinishedThe task outside of this JUnitResultFormatter is the <junit> task. So all tests passed and we could create the new java class.- Specified by:
- taskFinishedin interface- BuildListener
- Parameters:
- event- not used
- See Also:
 
- 
taskStartedNot used Signals that a task is starting.- Specified by:
- taskStartedin interface- BuildListener
- Parameters:
- event- An event with any relevant extra information. Must not be- null.
- See Also:
 
 
-