TestFailureListener

public class TestFailureListener
extends Object implements ITestInvocationListener

java.lang.Object
   ↳ com.android.tradefed.testtype.suite.TestFailureListener


Listener used to take action such as screenshot, bugreport, logcat collection upon a test failure when requested.

Summary

Public constructors

TestFailureListener(List<ITestDevice> devices, boolean bugReportOnFailure, boolean logcatOnFailure, boolean screenshotOnFailure, boolean rebootOnFailure, int maxLogcatBytes)

Public methods

void applyModuleConfiguration(boolean bugreportOnFailure, boolean logcatOnfailure, boolean screenshotOnFailure)

Allows to override the invocation settings of capture on failure by the module specific configurations.

void join()

Join on all the logcat capturing threads to ensure they terminate.

void setLogger(ITestLogger logger)

Sets where the logs should be saved.

void testEnded(TestDescription test, HashMap<String, MetricMeasurement.Metric> testMetrics)

Make sure we clean the map when test end to avoid too much overhead.

void testFailed(TestDescription test, String trace)

Reports the failure of a individual test case.

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

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

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

Forward the log to the logger, do not do it from whitin the #testLog callback as if TestFailureListener is part of the chain, it will results in an infinite loop.

void testStarted(TestDescription test)

We override testStarted in order to track the start time.

Public constructors

TestFailureListener

public TestFailureListener (List<ITestDevice> devices, 
                boolean bugReportOnFailure, 
                boolean logcatOnFailure, 
                boolean screenshotOnFailure, 
                boolean rebootOnFailure, 
                int maxLogcatBytes)

Parameters
devices List

bugReportOnFailure boolean

logcatOnFailure boolean

screenshotOnFailure boolean

rebootOnFailure boolean

maxLogcatBytes int

Public methods

applyModuleConfiguration

public void applyModuleConfiguration (boolean bugreportOnFailure, 
                boolean logcatOnfailure, 
                boolean screenshotOnFailure)

Allows to override the invocation settings of capture on failure by the module specific configurations.

Parameters
bugreportOnFailure boolean: true to capture a bugreport on test failure. False otherwise.

logcatOnfailure boolean: true to capture a logcat on test failure. False otherwise.

screenshotOnFailure boolean: true to capture a screenshot on failure. False otherwise.

join

public void join ()

Join on all the logcat capturing threads to ensure they terminate.

setLogger

public void setLogger (ITestLogger logger)

Sets where the logs should be saved.

Parameters
logger ITestLogger

testEnded

public void testEnded (TestDescription test, 
                HashMap<String, MetricMeasurement.Metric> testMetrics)

Make sure we clean the map when test end to avoid too much overhead.

Parameters
test TestDescription: identifies the test

testMetrics HashMap: a Map of the metrics emitted

testFailed

public void testFailed (TestDescription test, 
                String trace)

Reports the failure of a individual test case.

Will be called between testStarted and testEnded.

Parameters
test TestDescription: identifies the test

trace String: stack trace of failure

testLog

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

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

Must be called before ITestInvocationListener.invocationFailed(Throwable) or ITestInvocationListener.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.

testLogForward

public void testLogForward (String dataName, 
                LogDataType dataType, 
                InputStreamSource dataStream)

Forward the log to the logger, do not do it from whitin the #testLog callback as if TestFailureListener is part of the chain, it will results in an infinite loop.

Parameters
dataName String

dataType LogDataType

dataStream InputStreamSource

testStarted

public void testStarted (TestDescription test)

We override testStarted in order to track the start time.

Parameters
test TestDescription: identifies the test