Top Description Fields Constructors Methods
org.testng.reporters

public Class JUnitXMLReporter

extends Object
implements IResultListener2
Class Inheritance
All Implemented Interfaces
org.testng.internal.IResultListener2, org.testng.IConfigurationListener, org.testng.ITestNGListener, org.testng.internal.IResultListener, org.testng.ITestListener
Imports
java.net.InetAddress, .UnknownHostException, java.util.Collection, .Map, .Properties, .Queue, .Set, java.util.concurrent.ConcurrentLinkedDeque, java.util.regex.Pattern, org.testng.ITestContext, .ITestNGMethod, .ITestResult, org.testng.collections.Maps, .Sets, org.testng.internal.AutoCloseableLock, .IResultListener2, .Utils, org.testng.util.TimeUtils

A JUnit XML report generator (replacing the original JUnitXMLReporter that was based on XML APIs).
Author
Alex Popescu

Field Summary

Modifier and TypeField and Description
private static final Map<String, Pattern>
private static final Pattern
private static final Pattern
private static final Pattern
private final AutoCloseableLock
private Queue<ITestResult>
private Queue<ITestResult>
private int
private final Map<String, String>
private int
private static final Pattern
private static final Pattern

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
private void
private void
private String
pack-priv static String
private String

Returns:

unique name for the file associated with this test context.
generateFileName
(ITestContext
test context
context
)

This method guarantees unique file names for reports.

protected void
generateReport(ITestContext
The test context
context
)

generate the XML report given what we know from all the test results

private Set<String>
private Properties
getPropertiesFor(ITestNGMethod method, long elapsedTimeMillis)

public void
onConfigurationFailure(ITestResult
The test result
itr
)

Overrides default org.testng.IConfigurationListener.onConfigurationFailure.

Invoked whenever a configuration method failed.
public void
onConfigurationSkip(ITestResult
The test result
itr
)

Overrides default org.testng.IConfigurationListener.onConfigurationSkip.

Invoked whenever a configuration method was skipped.
public void
onConfigurationSuccess(ITestResult
The test result
itr
)

Overrides default org.testng.IConfigurationListener.onConfigurationSuccess.

Invoked whenever a configuration method succeeded.
public void
onFinish(ITestContext
The test context
context
)

Overrides default org.testng.ITestListener.onFinish.

Invoked after all the tests have run and all their Configuration methods have been called.
public void
onStart(ITestContext
The test context
context
)

Overrides default org.testng.ITestListener.onStart.

Invoked after the test class is instantiated and before any configuration method is called.
public void
onTestFailedButWithinSuccessPercentage(ITestResult
ITestResult containing information about the run test
tr
)

Overrides default org.testng.ITestListener.onTestFailedButWithinSuccessPercentage.

Invoked each time a method fails but has been annotated with successPercentage and this failure still keeps it within the success percentage requested.
public void
onTestFailure(ITestResult
ITestResult containing information about the run test
tr
)

Overrides default org.testng.ITestListener.onTestFailure.

Invoked each time a test fails.
public void
onTestSkipped(ITestResult
ITestResult containing information about the run test
tr
)

Overrides default org.testng.ITestListener.onTestSkipped.

Invoked each time a test is skipped.
public void
onTestSuccess(ITestResult
ITestResult containing information about the run test
tr
)

Overrides default org.testng.ITestListener.onTestSuccess.

Invoked each time a test succeeds.
private String
private void
resetAll()

Reset all member variables for next test.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ATTR_ESCAPESback to summary
private static final Map<String, Pattern> ATTR_ESCAPES
ENTITYback to summary
private static final Pattern ENTITY
GREATERback to summary
private static final Pattern GREATER
LESSback to summary
private static final Pattern LESS
lockback to summary
private final AutoCloseableLock lock
m_allTestsback to summary
private Queue<ITestResult> m_allTests
m_configIssuesback to summary
private Queue<ITestResult> m_configIssues
m_fileNameIncrementerback to summary
private int m_fileNameIncrementer
m_fileNameMapback to summary
private final Map<String, String> m_fileNameMap
m_numFailedback to summary
private int m_numFailed
QUOTEback to summary
private static final Pattern QUOTE
SINGLE_QUOTEback to summary
private static final Pattern SINGLE_QUOTE

Constructor Detail

JUnitXMLReporterback to summary
public JUnitXMLReporter()

Method Detail

createElementback to summary
private void createElement(XMLStringBuffer doc, ITestResult tr)
createElementFromIgnoredTestsback to summary
private void createElementFromIgnoredTests(XMLStringBuffer doc, ITestContext context)
createElementFromTestResultsback to summary
private void createElementFromTestResults(XMLStringBuffer document, Collection<ITestResult> results)
createFailureElementback to summary
private void createFailureElement(XMLStringBuffer doc, ITestResult tr)
createSkipElementback to summary
private void createSkipElement(XMLStringBuffer doc)
encodeAttrback to summary
private String encodeAttr(String attr)
formattedTimeback to summary
pack-priv static String formattedTime()
generateFileNameback to summary
private 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:ITestContext

test context

Returns:String

unique name for the file associated with this test context.

generateReportback to summary
protected void generateReport(ITestContext context)

generate the XML report given what we know from all the test results

Parameters
context:ITestContext

The test context

getPackagesback to summary
private Set<String> getPackages(ITestContext context)
getPropertiesForback to summary
private Properties getPropertiesFor(ITestNGMethod method, long elapsedTimeMillis)
onConfigurationFailureback to summary
public void onConfigurationFailure(ITestResult itr)

Overrides default org.testng.IConfigurationListener.onConfigurationFailure.

Doc from org.testng.IConfigurationListener.onConfigurationFailure.

Invoked whenever a configuration method failed.

Parameters
itr:ITestResult

The test result

Annotations
@Override
See Also
org.testng.IConfigurationListener#onConfigurationFailure(org.testng.ITestResult)
onConfigurationSkipback to summary
public void onConfigurationSkip(ITestResult itr)

Overrides default org.testng.IConfigurationListener.onConfigurationSkip.

Doc from org.testng.IConfigurationListener.onConfigurationSkip.

Invoked whenever a configuration method was skipped.

Parameters
itr:ITestResult

The test result

Annotations
@Override
See Also
org.testng.IConfigurationListener#onConfigurationSkip(org.testng.ITestResult)
onConfigurationSuccessback to summary
public void onConfigurationSuccess(ITestResult itr)

Overrides default org.testng.IConfigurationListener.onConfigurationSuccess.

Doc from org.testng.IConfigurationListener.onConfigurationSuccess.

Invoked whenever a configuration method succeeded.

Parameters
itr:ITestResult

The test result

Annotations
@Override
See Also
org.testng.IConfigurationListener#onConfigurationSuccess(org.testng.ITestResult)
onFinishback to summary
public void onFinish(ITestContext context)

Overrides default org.testng.ITestListener.onFinish.

Invoked after all the tests have run and all their Configuration methods have been called.

Parameters
context:ITestContext

Doc from org.testng.ITestListener.onFinish.

The test context

Annotations
@Override
onStartback to summary
public void onStart(ITestContext context)

Overrides default org.testng.ITestListener.onStart.

Invoked after the test class is instantiated and before any configuration method is called.

Parameters
context:ITestContext

Doc from org.testng.ITestListener.onStart.

The test context

Annotations
@Override
onTestFailedButWithinSuccessPercentageback to summary
public void onTestFailedButWithinSuccessPercentage(ITestResult tr)

Overrides default org.testng.ITestListener.onTestFailedButWithinSuccessPercentage.

Doc from org.testng.ITestListener.onTestFailedButWithinSuccessPercentage.

Invoked each time a method fails but has been annotated with successPercentage and this failure still keeps it within the success percentage requested.

Parameters
tr:ITestResult

ITestResult containing information about the run test

Annotations
@Override
onTestFailureback to summary
public void onTestFailure(ITestResult tr)

Overrides default org.testng.ITestListener.onTestFailure.

Invoked each time a test fails.

Parameters
tr:ITestResult

Doc from org.testng.ITestListener.onTestFailure.

ITestResult containing information about the run test

Annotations
@Override
onTestSkippedback to summary
public void onTestSkipped(ITestResult tr)

Overrides default org.testng.ITestListener.onTestSkipped.

Invoked each time a test is skipped.

Parameters
tr:ITestResult

Doc from org.testng.ITestListener.onTestSkipped.

ITestResult containing information about the run test

Annotations
@Override
onTestSuccessback to summary
public void onTestSuccess(ITestResult tr)

Overrides default org.testng.ITestListener.onTestSuccess.

Invoked each time a test succeeds.

Parameters
tr:ITestResult

Doc from org.testng.ITestListener.onTestSuccess.

ITestResult containing information about the run test

Annotations
@Override
replaceAmpersandback to summary
private String replaceAmpersand(String str)
resetAllback to summary
private void resetAll()

Reset all member variables for next test.