{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

TestRunResult

public class TestRunResult implements ITestRunListener


Holds results from a single test run.

Maintains an accurate count of tests, and tracks incomplete tests.

Not thread safe! The test* callbacks must be called in order

This is an android-compatible copy of com.android.ddmlib.testrunner.TestRunResult.

Summary

Public constructors

Create an emptyandroidx.test.orchestrator.listeners.result.TestRunResult.

Public methods

@NonNull Set<@NonNull TestIdentifier>

Gets the set of completed tests.

@NonNull long
@NonNull String
@NonNull int

Return total number of tests in a failure state (failed, assumption failure)

@NonNull int

Gets the number of complete tests in this run ie with status != incomplete.

@NonNull int

Gets the number of tests in this run.

@NonNull int

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

@NonNull String

Return the run failure error message, null if run did not fail.

@NonNull Map<@NonNull String, @NonNull String>
@NonNull Map<@NonNull TestIdentifier, @NonNull TestResult>

Gets a map of the test results.

@NonNull String

Return a user friendly string describing results.

@NonNull boolean
@NonNull boolean
@NonNull boolean
@NonNull void
setAggregateMetrics(@NonNull boolean metricAggregation)
@NonNull void
setRunComplete(@NonNull boolean runComplete)
@NonNull void

Called when an atomic test flags that it assumes a condition that is false

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

Reports the execution end of an individual test case.

@NonNull void

Reports the failure of a individual test case.

@NonNull void

Called when a test will not be run, generally because a test method is annotated with org.junit.Ignore.

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

Reports end of test run.

@NonNull void
testRunFailed(@NonNull String errorMessage)

Reports test run failed to complete due to a fatal error.

@NonNull void
testRunStarted(@NonNull String runName, @NonNull int testCount)

Reports the start of a test run.

@NonNull void
testRunStopped(@NonNull long elapsedTime)

Reports test run stopped before completion due to a user request.

@NonNull void

Reports the start of an individual test case.

Public constructors

TestRunResult

public TestRunResult()

Create an emptyandroidx.test.orchestrator.listeners.result.TestRunResult.

Public methods

getCompletedTests

@NonNull
public Set<@NonNull TestIdentifiergetCompletedTests()

Gets the set of completed tests.

getElapsedTime

@NonNull
public long getElapsedTime()
Returns
long

getName

@NonNull
public String getName()
Returns
String

the test run name

getNumAllFailedTests

@NonNull
public int getNumAllFailedTests()

Return total number of tests in a failure state (failed, assumption failure)

getNumCompleteTests

@NonNull
public int getNumCompleteTests()

Gets the number of complete tests in this run ie with status != incomplete.

getNumTests

@NonNull
public int getNumTests()

Gets the number of tests in this run.

getNumTestsInState

@NonNull
public int getNumTestsInState(@NonNull TestResult.TestStatus status)

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

getRunFailureMessage

@NonNull
public String getRunFailureMessage()

Return the run failure error message, null if run did not fail.

getRunMetrics

@NonNull
public Map<@NonNull String, @NonNull StringgetRunMetrics()
Returns
Map<@NonNull String, @NonNull String>

a Map of the test test run metrics.

getTestResults

@NonNull
public Map<@NonNull TestIdentifier, @NonNull TestResultgetTestResults()

Gets a map of the test results.

Returns
Map<@NonNull TestIdentifier, @NonNull TestResult>

getTextSummary

@NonNull
public String getTextSummary()

Return a user friendly string describing results.

Returns
String

hasFailedTests

@NonNull
public boolean hasFailedTests()
Returns
boolean

true if test run had any failed or error tests.

isRunComplete

@NonNull
public boolean isRunComplete()
Returns
boolean

true if test run finished.

isRunFailure

@NonNull
public boolean isRunFailure()
Returns
boolean

true if test run failed.

setAggregateMetrics

@NonNull
public void setAggregateMetrics(@NonNull boolean metricAggregation)

setRunComplete

@NonNull
public void setRunComplete(@NonNull boolean runComplete)

testAssumptionFailure

@NonNull
public void testAssumptionFailure(@NonNull TestIdentifier test, @NonNull String trace)

Called when an atomic test flags that it assumes a condition that is false

Parameters
@NonNull TestIdentifier test

identifies the test

@NonNull String trace

stack trace of failure

testEnded

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

Reports the execution end of an individual test case.

If testFailed was not invoked, this test passed. Also returns any key/value metrics which may have been emitted during the test case's execution.

Parameters
@NonNull TestIdentifier test

identifies the test

@NonNull Map<@NonNull String, @NonNull String> testMetrics

a Map of the metrics emitted

testFailed

@NonNull
public void testFailed(@NonNull TestIdentifier test, @NonNull String trace)

Reports the failure of a individual test case.

Will be called between testStarted and testEnded.

Parameters
@NonNull TestIdentifier test

identifies the test

@NonNull String trace

stack trace of failure

testIgnored

@NonNull
public void testIgnored(@NonNull TestIdentifier test)

Called when a test will not be run, generally because a test method is annotated with org.junit.Ignore.

Parameters
@NonNull TestIdentifier test

identifies the test

testRunEnded

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

Reports end of test run.

Parameters
@NonNull long elapsedTime

device reported elapsed time, in milliseconds

@NonNull Map<@NonNull String, @NonNull String> runMetrics

key-value pairs reported at the end of a test run

testRunFailed

@NonNull
public void testRunFailed(@NonNull String errorMessage)

Reports test run failed to complete due to a fatal error.

Parameters
@NonNull String errorMessage

String describing reason for run failure.

testRunStarted

@NonNull
public void testRunStarted(@NonNull String runName, @NonNull int testCount)

Reports the start of a test run.

Parameters
@NonNull String runName

the test run name

@NonNull int testCount

total number of tests in test run

testRunStopped

@NonNull
public void testRunStopped(@NonNull long elapsedTime)

Reports test run stopped before completion due to a user request.

TODO: currently unused, consider removing

Parameters
@NonNull long elapsedTime

device reported elapsed time, in milliseconds

testStarted

@NonNull
public void testStarted(@NonNull TestIdentifier test)

Reports the start of an individual test case.

Parameters
@NonNull TestIdentifier test

identifies the test