com.android.ddmlib.testrunner
Class XmlTestRunListener

java.lang.Object
  extended by com.android.ddmlib.testrunner.XmlTestRunListener
All Implemented Interfaces:
ITestRunListener

public class XmlTestRunListener
extends java.lang.Object
implements ITestRunListener

Writes JUnit results to an XML files in a format consistent with Ant's XMLJUnitResultFormatter.

Creates a separate XML file per test run.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.android.ddmlib.testrunner.ITestRunListener
ITestRunListener.TestFailure
 
Constructor Summary
XmlTestRunListener()
           
 
Method Summary
protected  java.io.File getResultFile(java.io.File reportDir)
          Creates a File where the report will be created.
 TestRunResult getRunResult()
          Returns the TestRunResult
protected  java.lang.String getTestName(TestIdentifier testId)
           
protected  java.lang.String getTestSuiteName()
           
 void setHostName(java.lang.String hostName)
           
protected  void setPropertiesAttributes(org.kxml2.io.KXmlSerializer serializer, java.lang.String namespace)
          Sets the attributes on properties.
 void setReportDir(java.io.File file)
          Sets the report file to use.
 void testEnded(TestIdentifier test, java.util.Map<java.lang.String,java.lang.String> testMetrics)
          Reports the execution end of an individual test case.
 void testFailed(ITestRunListener.TestFailure status, TestIdentifier test, java.lang.String trace)
          Reports the failure of a individual test case.
 void testRunEnded(long elapsedTime, java.util.Map<java.lang.String,java.lang.String> runMetrics)
          Reports end of test run.
 void testRunFailed(java.lang.String errorMessage)
          Reports test run failed to complete due to a fatal error.
 void testRunStarted(java.lang.String runName, int numTests)
          Reports the start of a test run.
 void testRunStopped(long arg0)
          Reports test run stopped before completion due to a user request.
 void testStarted(TestIdentifier test)
          Reports the start of an individual test case.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlTestRunListener

public XmlTestRunListener()
Method Detail

setReportDir

public void setReportDir(java.io.File file)
Sets the report file to use.


setHostName

public void setHostName(java.lang.String hostName)

getRunResult

public TestRunResult getRunResult()
Returns the TestRunResult

Returns:
the test run results.

testRunStarted

public void testRunStarted(java.lang.String runName,
                           int numTests)
Description copied from interface: ITestRunListener
Reports the start of a test run.

Specified by:
testRunStarted in interface ITestRunListener
Parameters:
runName - the test run name
numTests - total number of tests in test run

testStarted

public void testStarted(TestIdentifier test)
Description copied from interface: ITestRunListener
Reports the start of an individual test case.

Specified by:
testStarted in interface ITestRunListener
Parameters:
test - identifies the test

testFailed

public void testFailed(ITestRunListener.TestFailure status,
                       TestIdentifier test,
                       java.lang.String trace)
Description copied from interface: ITestRunListener
Reports the failure of a individual test case.

Will be called between testStarted and testEnded.

Specified by:
testFailed in interface ITestRunListener
Parameters:
status - failure type
test - identifies the test
trace - stack trace of failure

testEnded

public void testEnded(TestIdentifier test,
                      java.util.Map<java.lang.String,java.lang.String> testMetrics)
Description copied from interface: ITestRunListener
Reports the execution end of an individual test case.

If ITestRunListener.testFailed(com.android.ddmlib.testrunner.ITestRunListener.TestFailure, com.android.ddmlib.testrunner.TestIdentifier, java.lang.String) was not invoked, this test passed. Also returns any key/value metrics which may have been emitted during the test case's execution.

Specified by:
testEnded in interface ITestRunListener
Parameters:
test - identifies the test
testMetrics - a Map of the metrics emitted

testRunFailed

public void testRunFailed(java.lang.String errorMessage)
Description copied from interface: ITestRunListener
Reports test run failed to complete due to a fatal error.

Specified by:
testRunFailed in interface ITestRunListener
Parameters:
errorMessage - String describing reason for run failure.

testRunStopped

public void testRunStopped(long arg0)
Description copied from interface: ITestRunListener
Reports test run stopped before completion due to a user request.

TODO: currently unused, consider removing

Specified by:
testRunStopped in interface ITestRunListener
Parameters:
arg0 - device reported elapsed time, in milliseconds

testRunEnded

public void testRunEnded(long elapsedTime,
                         java.util.Map<java.lang.String,java.lang.String> runMetrics)
Description copied from interface: ITestRunListener
Reports end of test run.

Specified by:
testRunEnded in interface ITestRunListener
Parameters:
elapsedTime - device reported elapsed time, in milliseconds
runMetrics - key-value pairs reported at the end of a test run

getResultFile

protected java.io.File getResultFile(java.io.File reportDir)
                              throws java.io.IOException
Creates a File where the report will be created.

Parameters:
reportDir - the root directory of the report.
Returns:
a file
Throws:
java.io.IOException

getTestSuiteName

protected java.lang.String getTestSuiteName()

setPropertiesAttributes

protected void setPropertiesAttributes(org.kxml2.io.KXmlSerializer serializer,
                                       java.lang.String namespace)
                                throws java.io.IOException
Sets the attributes on properties.

Parameters:
serializer - the serializer
namespace - the namespace
Throws:
java.io.IOException

getTestName

protected java.lang.String getTestName(TestIdentifier testId)