CollectingTestListener

public class CollectingTestListener
extends Object implements ITestInvocationListener

java.lang.Object
   ↳ com.android.tradefed.result.CollectingTestListener
Known Direct Subclasses
ConsoleResultReporter Result reporter to print the test results to the console. 
EmailResultReporter A simple result reporter base class that sends emails for test results. 
JsonHttpTestResultReporter A result reporter that encode test metrics results and branch, device info into JSON and POST into an HTTP service endpoint  
ModuleListener Listener attached to each IRemoteTest of each module in order to collect the list of results. 
ShardListener A ITestInvocationListener that collects results from a invocation shard (aka an invocation split to run on multiple resources in parallel), and forwards them to another listener. 
SuiteResultReporter Collect test results for an entire suite invocation and output the final results. 
XmlResultReporter Writes JUnit results to an XML files in a format consistent with Ant's XMLJUnitResultFormatter. 
Known Indirect Subclasses
DeviceUnavailEmailResultReporter An EmailResultReporter that will send email when invocation fails due to a device not available exception. 
FailureEmailResultReporter An EmailResultReporter that sends notifications if either a test failure or invocation failure occurred. 
InvocationFailureEmailResultReporter An EmailResultReporter that can also restrict notifications to just invocation failures. 
TestFailureEmailResultReporter An EmailResultReporter that can also restrict notifications to just test failures. 


A ITestInvocationListener that will collect all test results.

Although the data structures used in this object are thread-safe, the ITestInvocationListener callbacks must be called in the correct order.

Summary

Public constructors

CollectingTestListener()

Public methods

IBuildInfo getBuildInfo()

This method is deprecated. rely on the IBuildInfo from getInvocationContext().

TestRunResult getCurrentRunResults()

Gets the results for the current test run.

IInvocationContext getInvocationContext()

Return the invocation context that was reported via invocationStarted(IInvocationContext)

IInvocationContext getModuleContextForRunResult(TestRunResult res)

Returns the IInvocationContext of the module associated with the results or null if it was not associated with any module.

int getNumAllFailedTests()

Return total number of tests in a failure state (only failed, assumption failures do not count toward it).

int getNumTestsInState(TestResult.TestStatus status)

Gets the number of tests in given state for this run.

int getNumTotalTests()

Gets the total number of complete tests for all runs.

IBuildInfo getPrimaryBuildInfo()

Return the primary build info that was reported via invocationStarted(IInvocationContext).

Collection<TestRunResult> getRunResults()

Gets the results for all test runs.

TestSummary getSummary()

Allows the InvocationListener to return a summary.

boolean hasFailedTests()
boolean hasResultFor(String runName)

Returns True if the result map already has an entry for the run name.

void invocationEnded(long elapsedTime)

Reports that the invocation has terminated, whether successfully or due to some error condition.

void invocationFailed(Throwable cause)

Reports an incomplete invocation due to some error condition.

void invocationStarted(IInvocationContext context)

Reports the start of the test invocation.

void setBuildInfo(IBuildInfo buildInfo)

This method is deprecated. Not necessary for testing anymore.

void testAssumptionFailure(TestIdentifier test, String trace)

void testEnded(TestIdentifier test, long endTime, Map<String, String> testMetrics)

void testEnded(TestIdentifier test, Map<String, String> testMetrics)

void testFailed(TestIdentifier test, String trace)

void testIgnored(TestIdentifier test)

void testLog(String dataName, LogDataType dataType, InputStreamSource dataStream)

Provides the associated log or debug data from the test invocation.

void testModuleEnded()

Reports the end of a module run.

void testModuleStarted(IInvocationContext moduleContext)

Reports the beginning of a module running.

void testRunEnded(long elapsedTime, Map<String, String> runMetrics)

void testRunFailed(String errorMessage)

void testRunStarted(String name, int numTests)

void testRunStopped(long elapsedTime)

void testStarted(TestIdentifier test)

void testStarted(TestIdentifier test, long startTime)

Protected methods

void setIsAggregrateMetrics(boolean aggregate)

Toggle the 'aggregate metrics' option

Public constructors

CollectingTestListener

CollectingTestListener ()

Public methods

getBuildInfo

IBuildInfo getBuildInfo ()

This method is deprecated.
rely on the IBuildInfo from getInvocationContext().

Returns the build info.

Returns
IBuildInfo

getCurrentRunResults

TestRunResult getCurrentRunResults ()

Gets the results for the current test run.

Note the results may not be complete. It is recommended to test the value of isRunComplete() and/or (@link TestRunResult#isRunFailure()} as appropriate before processing the results.

Returns
TestRunResult the TestRunResult representing data collected during last test run

getInvocationContext

IInvocationContext getInvocationContext ()

Return the invocation context that was reported via invocationStarted(IInvocationContext)

Returns
IInvocationContext

getModuleContextForRunResult

IInvocationContext getModuleContextForRunResult (TestRunResult res)

Returns the IInvocationContext of the module associated with the results or null if it was not associated with any module.

Parameters
res TestRunResult

Returns
IInvocationContext

getNumAllFailedTests

int getNumAllFailedTests ()

Return total number of tests in a failure state (only failed, assumption failures do not count toward it).

Returns
int

getNumTestsInState

int getNumTestsInState (TestResult.TestStatus status)

Gets the number of tests in given state for this run.

Parameters
status TestResult.TestStatus

Returns
int

getNumTotalTests

int getNumTotalTests ()

Gets the total number of complete tests for all runs.

Returns
int

getPrimaryBuildInfo

IBuildInfo getPrimaryBuildInfo ()

Return the primary build info that was reported via invocationStarted(IInvocationContext). Primary build is the build returned by the first build provider of the running configuration. Returns null if there is no context (no build to test case).

Returns
IBuildInfo

getRunResults

Collection<TestRunResult> getRunResults ()

Gets the results for all test runs.

Returns
Collection<TestRunResult>

getSummary

TestSummary getSummary ()

Allows the InvocationListener to return a summary.

Returns
TestSummary A TestSummary summarizing the run, or null

hasFailedTests

boolean hasFailedTests ()

Returns
boolean true if invocation had any failed or assumption failed tests.

hasResultFor

boolean hasResultFor (String runName)

Returns True if the result map already has an entry for the run name.

Parameters
runName String

Returns
boolean

invocationEnded

void invocationEnded (long elapsedTime)

Reports that the invocation has terminated, whether successfully or due to some error condition.

Will be automatically called by the TradeFederation framework.

Parameters
elapsedTime long: the elapsed time of the invocation in ms

invocationFailed

void invocationFailed (Throwable cause)

Reports an incomplete invocation due to some error condition.

Will be automatically called by the TradeFederation framework.

Parameters
cause Throwable: the Throwable cause of the failure

invocationStarted

void invocationStarted (IInvocationContext context)

Reports the start of the test invocation.

Will be automatically called by the TradeFederation framework. Reporters need to override this method to support multiple devices reporting.

Parameters
context IInvocationContext: information about the invocation

setBuildInfo

void setBuildInfo (IBuildInfo buildInfo)

This method is deprecated.
Not necessary for testing anymore.

Set the build info. Should only be used for testing.

Parameters
buildInfo IBuildInfo

testAssumptionFailure

void testAssumptionFailure (TestIdentifier test, 
                String trace)

Parameters
test TestIdentifier

trace String

testEnded

void testEnded (TestIdentifier test, 
                long endTime, 
                Map<String, String> testMetrics)

Parameters
test TestIdentifier

endTime long

testMetrics Map

testEnded

void testEnded (TestIdentifier test, 
                Map<String, String> testMetrics)

Parameters
test TestIdentifier

testMetrics Map

testFailed

void testFailed (TestIdentifier test, 
                String trace)

Parameters
test TestIdentifier

trace String

testIgnored

void testIgnored (TestIdentifier test)

Parameters
test TestIdentifier

testLog

void testLog (String dataName, 
                LogDataType dataType, 
                InputStreamSource dataStream)

Provides the associated log or debug data from the test invocation.

Must be called before invocationFailed(Throwable) or invocationEnded(long)

The TradeFederation framework will automatically call this method, providing the host log and if applicable, the device logcat.

Parameters
dataName String: a String descriptive name of the data. e.g. "device_logcat". Note dataName may not be unique per invocation. ie implementers must be able to handle multiple calls with same dataName

dataType LogDataType: the LogDataType of the data

dataStream InputStreamSource: the InputStreamSource of the data. Implementers should call createInputStream to start reading the data, and ensure to close the resulting InputStream when complete. Callers should ensure the source of the data remains present and accessible until the testLog method completes.

testModuleEnded

void testModuleEnded ()

Reports the end of a module run.

testModuleStarted

void testModuleStarted (IInvocationContext moduleContext)

Reports the beginning of a module running. This callback is associated with testModuleEnded() and is optional in the sequence. It is only used during a run that uses modules: ITestSuite based runners.

Parameters
moduleContext IInvocationContext: the IInvocationContext of the module.

testRunEnded

void testRunEnded (long elapsedTime, 
                Map<String, String> runMetrics)

Parameters
elapsedTime long

runMetrics Map

testRunFailed

void testRunFailed (String errorMessage)

Parameters
errorMessage String

testRunStarted

void testRunStarted (String name, 
                int numTests)

Parameters
name String

numTests int

testRunStopped

void testRunStopped (long elapsedTime)

Parameters
elapsedTime long

testStarted

void testStarted (TestIdentifier test)

Parameters
test TestIdentifier

testStarted

void testStarted (TestIdentifier test, 
                long startTime)

Parameters
test TestIdentifier

startTime long

Protected methods

setIsAggregrateMetrics

void setIsAggregrateMetrics (boolean aggregate)

Toggle the 'aggregate metrics' option

Parameters
aggregate boolean