Class FailureRecorder

  • All Implemented Interfaces:
    java.lang.Cloneable, java.util.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
    • Field Detail

      • MAGIC_PROPERTY_CLASS_LOCATION

        public static final java.lang.String MAGIC_PROPERTY_CLASS_LOCATION
        This 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_LOCATION, Constant Field Values
      • DEFAULT_CLASS_LOCATION

        public static final java.lang.String DEFAULT_CLASS_LOCATION
        Default location and name for the generated JUnit class file, in the temp directory + FailedTests
    • Constructor Detail

      • FailureRecorder

        public FailureRecorder()
    • Method Detail

      • 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.
        Overrides:
        setProject in class ProjectComponent
        Parameters:
        project - project reference
      • addError

        public void addError​(junit.framework.Test test,
                             java.lang.Throwable throwable)
        Add the failed test to the list.
        Specified by:
        addError in interface junit.framework.TestListener
        Parameters:
        test - the test that erred.
        throwable - the reason it erred.
        See Also:
        TestListener.addError(junit.framework.Test, java.lang.Throwable)
      • addFailure

        public void addFailure​(junit.framework.Test test,
                               junit.framework.AssertionFailedError error)
        Add the failed test to the list.
        Specified by:
        addFailure in interface junit.framework.TestListener
        Parameters:
        test - the test that failed.
        error - the assertion that failed.
        See Also:
        TestListener.addFailure(junit.framework.Test, junit.framework.AssertionFailedError)
      • setSystemError

        public void setSystemError​(java.lang.String err)
        Not used This is what the test has written to System.err
        Specified by:
        setSystemError in interface JUnitResultFormatter
        Parameters:
        err - the string to write.
      • setSystemOutput

        public void setSystemOutput​(java.lang.String out)
        Not used This is what the test has written to System.out
        Specified by:
        setSystemOutput in interface JUnitResultFormatter
        Parameters:
        out - the string to write.
      • endTest

        public void endTest​(junit.framework.Test test)
        Not used
        Specified by:
        endTest in interface junit.framework.TestListener
      • startTest

        public void startTest​(junit.framework.Test test)
        Not used
        Specified by:
        startTest in interface junit.framework.TestListener
      • log

        public void log​(java.lang.String message)
        Logging facade in INFO-mode.
        Overrides:
        log in class ProjectComponent
        Parameters:
        message - Log-message
      • verbose

        public void verbose​(java.lang.String message)
        Logging facade in VERBOSE-mode.
        Parameters:
        message - Log-message
      • buildFinished

        public void buildFinished​(BuildEvent event)
        Not used Signals that the last target has finished. This event will still be fired if an error occurred during the build.
        Specified by:
        buildFinished in interface BuildListener
        Parameters:
        event - An event with any relevant extra information. Must not be null.
        See Also:
        BuildEvent.getException()
      • buildStarted

        public void buildStarted​(BuildEvent event)
        Not 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:
        buildStarted in interface BuildListener
        Parameters:
        event - An event with any relevant extra information. Must not be null.
      • targetFinished

        public void targetFinished​(BuildEvent event)
        Not used Signals that a target has finished. This event will still be fired if an error occurred during the build.
        Specified by:
        targetFinished in interface BuildListener
        Parameters:
        event - An event with any relevant extra information. Must not be null.
        See Also:
        BuildEvent.getException()
      • taskStarted

        public void taskStarted​(BuildEvent event)
        Not used Signals that a task is starting.
        Specified by:
        taskStarted in interface BuildListener
        Parameters:
        event - An event with any relevant extra information. Must not be null.
        See Also:
        BuildEvent.getTask()