Package org.fest.swing.junit.ant
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final EnvironmentXmlNodeWriter
private OutputStream
private final SuiteXmlNodeWriter
private final TestCollection
private final TestXmlNodeWriter
private final XmlOutputWriter
private XmlNode
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
An error occurred while running the test.final void
addFailure
(junit.framework.Test test, Throwable error) A test failed.final void
addFailure
(junit.framework.Test test, junit.framework.AssertionFailedError failedAssertion) A test failed.final void
endTest
(junit.framework.Test test) A test is finished.final void
endTestSuite
(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest suite) The whole test suite ended.private XmlNode
formatError
(String type, junit.framework.Test test, Throwable error) private void
formatOutput
(String type, String output) 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.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.final void
setOutput
(OutputStream out) Sets the stream the formatter is supposed to write its results to.final void
setSystemError
(String out) This is what the test has written toSystem.err
.final void
setSystemOutput
(String out) This is what the test has written toSystem.out
,final void
startTest
(junit.framework.Test test) A new test is started.final void
startTestSuite
(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest suite) The whole test suite started.(package private) final TestCollection
tests()
protected final void
writeErrorAndStackTrace
(Throwable error, XmlNode errorXmlNode) Writes the stack trace and message of the given error to the given XML node.private XmlNode
xmlForFailed
(junit.framework.Test test) private XmlNode
xmlNodeForFinished
(junit.framework.Test test) protected final XmlNode
-
Field Details
-
xmlRoot
-
out
-
tests
-
suiteXmlNodeWriter
-
environmentXmlNodeWriter
-
testXmlNodeWriter
-
xmlOutputWriter
-
-
Constructor Details
-
XmlJUnitResultFormatter
public XmlJUnitResultFormatter()Creates a newXmlJUnitResultFormatter
.
-
-
Method Details
-
tests
-
setOutput
Sets the stream the formatter is supposed to write its results to.- Specified by:
setOutput
in interfaceorg.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
- Specified by:
setOutput
in interfaceorg.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirror.JUnitResultFormatterMirror
- Parameters:
out
- the output stream to use.
-
setSystemOutput
This is what the test has written toSystem.out
,- Specified by:
setSystemOutput
in interfaceorg.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
- Parameters:
out
- theString
to write.
-
setSystemError
This is what the test has written toSystem.err
.- Specified by:
setSystemError
in interfaceorg.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter
- Parameters:
out
- theString
to write.
-
formatOutput
-
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 interfaceorg.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 interfaceorg.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 interfacejunit.framework.TestListener
- Parameters:
test
- the test.
-
endTest
public final void endTest(junit.framework.Test test) A test is finished.- Specified by:
endTest
in interfacejunit.framework.TestListener
- Parameters:
test
- the test.
-
xmlNodeForFinished
-
addFailure
public final void addFailure(junit.framework.Test test, junit.framework.AssertionFailedError failedAssertion) A test failed.- Specified by:
addFailure
in interfacejunit.framework.TestListener
- Parameters:
test
- the test.failedAssertion
- the failed assertion.
-
addFailure
A test failed.- Parameters:
test
- the test.error
- the exception.
-
addError
An error occurred while running the test.- Specified by:
addError
in interfacejunit.framework.TestListener
- Parameters:
test
- the test.error
- the error.
-
formatError
-
xmlForFailed
-
writeErrorAndStackTrace
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
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.
-