Class XmlJUnitResultFormatter

java.lang.Object
org.fest.swing.junit.ant.XmlJUnitResultFormatter
All Implemented Interfaces:
junit.framework.TestListener, org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter, org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirror.JUnitResultFormatterMirror
Direct Known Subclasses:
ScreenshotOnFailureResultFormatter

public class XmlJUnitResultFormatter extends Object implements org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
Understands a copy of the original XMLJUnitResultFormatter, with flexibility for extension.
  • Field Details

  • Constructor Details

  • Method Details

    • tests

      final TestCollection tests()
    • setOutput

      public final void setOutput(OutputStream out)
      Sets the stream the formatter is supposed to write its results to.
      Specified by:
      setOutput in interface org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
      Specified by:
      setOutput in interface org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirror.JUnitResultFormatterMirror
      Parameters:
      out - the output stream to use.
    • setSystemOutput

      public final void setSystemOutput(String out)
      This is what the test has written to System.out,
      Specified by:
      setSystemOutput in interface org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
      Parameters:
      out - the String to write.
    • setSystemError

      public final void setSystemError(String out)
      This is what the test has written to System.err.
      Specified by:
      setSystemError in interface org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
      Parameters:
      out - the String to write.
    • formatOutput

      private void formatOutput(String type, String output)
    • xmlRootNode

      protected final XmlNode xmlRootNode()
    • startTestSuite

      public final void startTestSuite(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest suite)
      The whole test suite started. This method starts creation of the XML report.
      Specified by:
      startTestSuite in interface org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
      Parameters:
      suite - the test suite.
      Throws:
      ExceptionInInitializerError - if the underlying XML document could not be created.
    • onStartTestSuite

      protected void onStartTestSuite(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest suite)
      Hook for subclasses to add extra functionality after the whole test suite started.
      Parameters:
      suite - the test suite.
    • endTestSuite

      public final void endTestSuite(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest suite)
      The whole test suite ended. This method finishes writing the XML report and writes its contents to this formatter's OutputStream.
      Specified by:
      endTestSuite in interface org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
      Parameters:
      suite - the test suite.
      Throws:
      org.apache.tools.ant.BuildException - on error.
    • startTest

      public final void startTest(junit.framework.Test test)
      A new test is started.
      Specified by:
      startTest in interface junit.framework.TestListener
      Parameters:
      test - the test.
    • endTest

      public final void endTest(junit.framework.Test test)
      A test is finished.
      Specified by:
      endTest in interface junit.framework.TestListener
      Parameters:
      test - the test.
    • xmlNodeForFinished

      private XmlNode xmlNodeForFinished(junit.framework.Test test)
    • addFailure

      public final void addFailure(junit.framework.Test test, junit.framework.AssertionFailedError failedAssertion)
      A test failed.
      Specified by:
      addFailure in interface junit.framework.TestListener
      Parameters:
      test - the test.
      failedAssertion - the failed assertion.
    • addFailure

      public final void addFailure(junit.framework.Test test, Throwable error)
      A test failed.
      Parameters:
      test - the test.
      error - the exception.
    • addError

      public final void addError(junit.framework.Test test, Throwable error)
      An error occurred while running the test.
      Specified by:
      addError in interface junit.framework.TestListener
      Parameters:
      test - the test.
      error - the error.
    • formatError

      private XmlNode formatError(String type, junit.framework.Test test, Throwable error)
    • xmlForFailed

      private XmlNode xmlForFailed(junit.framework.Test test)
    • writeErrorAndStackTrace

      protected final void writeErrorAndStackTrace(Throwable error, XmlNode errorXmlNode)
      Writes the stack trace and message of the given error to the given XML node.
      Parameters:
      error - the given error.
      errorXmlNode - the XML node to write to.
    • onFailureOrError

      protected void onFailureOrError(junit.framework.Test test, Throwable error, XmlNode errorXmlNode)
      Hook for subclasses to add extra functionality after a test failure or a test execution error.
      Parameters:
      test - the executing test.
      error - the reason of the failure or error.
      errorXmlNode - the XML element containing information about the test failure or error.