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 EnvironmentXmlNodeWriterprivate OutputStreamprivate final SuiteXmlNodeWriterprivate final TestCollectionprivate final TestXmlNodeWriterprivate final XmlOutputWriterprivate XmlNode -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAn error occurred while running the test.final voidaddFailure(junit.framework.Test test, Throwable error) A test failed.final voidaddFailure(junit.framework.Test test, junit.framework.AssertionFailedError failedAssertion) A test failed.final voidendTest(junit.framework.Test test) A test is finished.final voidendTestSuite(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest suite) The whole test suite ended.private XmlNodeformatError(String type, junit.framework.Test test, Throwable error) private voidformatOutput(String type, String output) protected voidonFailureOrError(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 voidonStartTestSuite(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest suite) Hook for subclasses to add extra functionality after the whole test suite started.final voidsetOutput(OutputStream out) Sets the stream the formatter is supposed to write its results to.final voidsetSystemError(String out) This is what the test has written toSystem.err.final voidsetSystemOutput(String out) This is what the test has written toSystem.out,final voidstartTest(junit.framework.Test test) A new test is started.final voidstartTestSuite(org.apache.tools.ant.taskdefs.optional.junit.JUnitTest suite) The whole test suite started.(package private) final TestCollectiontests()protected final voidwriteErrorAndStackTrace(Throwable error, XmlNode errorXmlNode) Writes the stack trace and message of the given error to the given XML node.private XmlNodexmlForFailed(junit.framework.Test test) private XmlNodexmlNodeForFinished(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:
setOutputin interfaceorg.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter- Specified by:
setOutputin 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:
setSystemOutputin interfaceorg.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter- Parameters:
out- theStringto write.
-
setSystemError
This is what the test has written toSystem.err.- Specified by:
setSystemErrorin interfaceorg.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter- Parameters:
out- theStringto 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:
startTestSuitein 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:
endTestSuitein 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:
startTestin interfacejunit.framework.TestListener- Parameters:
test- the test.
-
endTest
public final void endTest(junit.framework.Test test) A test is finished.- Specified by:
endTestin 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:
addFailurein 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:
addErrorin 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.
-