Package org.testng.reporters
Class JUnitXMLReporter
- java.lang.Object
-
- org.testng.reporters.JUnitXMLReporter
-
- All Implemented Interfaces:
IConfigurationListener,IResultListener,IResultListener2,ITestListener,ITestNGListener
public class JUnitXMLReporter extends java.lang.Object implements IResultListener2
A JUnit XML report generator (replacing the original JUnitXMLReporter that was based on XML APIs).
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,java.util.regex.Pattern>ATTR_ESCAPESprivate static java.util.regex.PatternENTITYprivate static java.util.regex.PatternGREATERprivate static java.util.regex.PatternLESSprivate java.util.Queue<ITestResult>m_allTestsprivate java.util.Queue<ITestResult>m_configIssuesprivate intm_fileNameIncrementerprivate java.util.Map<java.lang.String,java.lang.String>m_fileNameMapprivate intm_numFailedprivate static java.util.regex.PatternQUOTEprivate static java.util.regex.PatternSINGLE_QUOTE
-
Constructor Summary
Constructors Constructor Description JUnitXMLReporter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeforeConfiguration(ITestResult tr)Invoked before a configuration method is invoked.private voidcreateElement(XMLStringBuffer doc, ITestResult tr)private voidcreateElementFromIgnoredTests(XMLStringBuffer doc, ITestContext context)private voidcreateElementFromTestResults(XMLStringBuffer document, java.util.Collection<ITestResult> results)private voidcreateFailureElement(XMLStringBuffer doc, ITestResult tr)private voidcreateSkipElement(XMLStringBuffer doc)private java.lang.StringencodeAttr(java.lang.String attr)(package private) static java.lang.StringformattedTime()private java.lang.StringgenerateFileName(ITestContext context)This method guarantees unique file names for reports.
Also, this will guarantee that the old reports are overwritten when tests are run again.protected voidgenerateReport(ITestContext context)generate the XML report given what we know from all the test resultsprivate java.util.Set<java.lang.String>getPackages(ITestContext context)private java.util.PropertiesgetPropertiesFor(ITestNGMethod method, long elapsedTimeMillis)voidonConfigurationFailure(ITestResult itr)Invoked whenever a configuration method failed.voidonConfigurationSkip(ITestResult itr)Invoked whenever a configuration method was skipped.voidonConfigurationSuccess(ITestResult itr)Invoked whenever a configuration method succeeded.voidonFinish(ITestContext context)Invoked after all the tests have run and all their Configuration methods have been called.voidonStart(ITestContext context)Invoked after the test class is instantiated and before any configuration method is called.voidonTestFailedButWithinSuccessPercentage(ITestResult tr)Invoked each time a method fails but has been annotated with successPercentage and this failure still keeps it within the success percentage requested.voidonTestFailure(ITestResult tr)Invoked each time a test fails.voidonTestSkipped(ITestResult tr)Invoked each time a test is skipped.voidonTestStart(ITestResult result)Invoked each time before a test will be invoked.voidonTestSuccess(ITestResult tr)Invoked each time a test succeeds.private java.lang.StringreplaceAmpersand(java.lang.String str, java.util.regex.Pattern pattern)private voidresetAll()Reset all member variables for next test.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.testng.IConfigurationListener
beforeConfiguration, onConfigurationFailure, onConfigurationSkip, onConfigurationSuccess
-
Methods inherited from interface org.testng.ITestListener
onTestFailedWithTimeout
-
-
-
-
Field Detail
-
ENTITY
private static final java.util.regex.Pattern ENTITY
-
LESS
private static final java.util.regex.Pattern LESS
-
GREATER
private static final java.util.regex.Pattern GREATER
-
SINGLE_QUOTE
private static final java.util.regex.Pattern SINGLE_QUOTE
-
QUOTE
private static final java.util.regex.Pattern QUOTE
-
ATTR_ESCAPES
private static final java.util.Map<java.lang.String,java.util.regex.Pattern> ATTR_ESCAPES
-
m_numFailed
private int m_numFailed
-
m_allTests
private java.util.Queue<ITestResult> m_allTests
-
m_configIssues
private java.util.Queue<ITestResult> m_configIssues
-
m_fileNameMap
private java.util.Map<java.lang.String,java.lang.String> m_fileNameMap
-
m_fileNameIncrementer
private int m_fileNameIncrementer
-
-
Method Detail
-
onTestStart
public void onTestStart(ITestResult result)
Description copied from interface:ITestListenerInvoked each time before a test will be invoked. TheITestResultis only partially filled with the references to class, method, start millis and status.- Specified by:
onTestStartin interfaceITestListener- Parameters:
result- the partially filledITestResult- See Also:
ITestResult.STARTED
-
beforeConfiguration
public void beforeConfiguration(ITestResult tr)
Description copied from interface:IConfigurationListenerInvoked before a configuration method is invoked.- Specified by:
beforeConfigurationin interfaceIConfigurationListener- Parameters:
tr- The test result
-
onTestSuccess
public void onTestSuccess(ITestResult tr)
Invoked each time a test succeeds.- Specified by:
onTestSuccessin interfaceITestListener- Parameters:
tr-ITestResultcontaining information about the run test- See Also:
ITestResult.SUCCESS
-
onTestFailedButWithinSuccessPercentage
public void onTestFailedButWithinSuccessPercentage(ITestResult tr)
Description copied from interface:ITestListenerInvoked each time a method fails but has been annotated with successPercentage and this failure still keeps it within the success percentage requested.- Specified by:
onTestFailedButWithinSuccessPercentagein interfaceITestListener- Parameters:
tr-ITestResultcontaining information about the run test- See Also:
ITestResult.SUCCESS_PERCENTAGE_FAILURE
-
onTestFailure
public void onTestFailure(ITestResult tr)
Invoked each time a test fails.- Specified by:
onTestFailurein interfaceITestListener- Parameters:
tr-ITestResultcontaining information about the run test- See Also:
ITestResult.FAILURE
-
onTestSkipped
public void onTestSkipped(ITestResult tr)
Invoked each time a test is skipped.- Specified by:
onTestSkippedin interfaceITestListener- Parameters:
tr-ITestResultcontaining information about the run test- See Also:
ITestResult.SKIP
-
onStart
public void onStart(ITestContext context)
Invoked after the test class is instantiated and before any configuration method is called.- Specified by:
onStartin interfaceITestListener- Parameters:
context- The test context
-
onFinish
public void onFinish(ITestContext context)
Invoked after all the tests have run and all their Configuration methods have been called.- Specified by:
onFinishin interfaceITestListener- Parameters:
context- The test context
-
onConfigurationFailure
public void onConfigurationFailure(ITestResult itr)
Description copied from interface:IConfigurationListenerInvoked whenever a configuration method failed.- Specified by:
onConfigurationFailurein interfaceIConfigurationListener- Parameters:
itr- The test result- See Also:
IConfigurationListener.onConfigurationFailure(org.testng.ITestResult)
-
onConfigurationSkip
public void onConfigurationSkip(ITestResult itr)
Description copied from interface:IConfigurationListenerInvoked whenever a configuration method was skipped.- Specified by:
onConfigurationSkipin interfaceIConfigurationListener- Parameters:
itr- The test result- See Also:
IConfigurationListener.onConfigurationSkip(org.testng.ITestResult)
-
onConfigurationSuccess
public void onConfigurationSuccess(ITestResult itr)
Description copied from interface:IConfigurationListenerInvoked whenever a configuration method succeeded.- Specified by:
onConfigurationSuccessin interfaceIConfigurationListener- Parameters:
itr- The test result- See Also:
IConfigurationListener.onConfigurationSuccess(org.testng.ITestResult)
-
generateReport
protected void generateReport(ITestContext context)
generate the XML report given what we know from all the test results- Parameters:
context- The test context
-
formattedTime
static java.lang.String formattedTime()
-
createElementFromTestResults
private void createElementFromTestResults(XMLStringBuffer document, java.util.Collection<ITestResult> results)
-
createElementFromIgnoredTests
private void createElementFromIgnoredTests(XMLStringBuffer doc, ITestContext context)
-
getPropertiesFor
private java.util.Properties getPropertiesFor(ITestNGMethod method, long elapsedTimeMillis)
-
getPackages
private java.util.Set<java.lang.String> getPackages(ITestContext context)
-
createElement
private void createElement(XMLStringBuffer doc, ITestResult tr)
-
createFailureElement
private void createFailureElement(XMLStringBuffer doc, ITestResult tr)
-
createSkipElement
private void createSkipElement(XMLStringBuffer doc)
-
encodeAttr
private java.lang.String encodeAttr(java.lang.String attr)
-
replaceAmpersand
private java.lang.String replaceAmpersand(java.lang.String str, java.util.regex.Pattern pattern)
-
resetAll
private void resetAll()
Reset all member variables for next test.
-
generateFileName
private java.lang.String generateFileName(ITestContext context)
This method guarantees unique file names for reports.
Also, this will guarantee that the old reports are overwritten when tests are run again.- Parameters:
context- test context- Returns:
- unique name for the file associated with this test context.
-
-