ITestLifeCycleReceiver

public interface ITestLifeCycleReceiver

com.android.tradefed.result.ITestLifeCycleReceiver


在仪器测试运行期间接收事件通知。

模仿 org.junit.runner.notification.RunListener

调用顺序将是:

  • 测试运行开始
  • 测试开始
  • [测试失败]
  • [测试假设失败]
  • [测试忽略]
  • 测试结束
  • ....
  • [测试运行失败]
  • 测试运行结束

概括

公共方法

default void testAssumptionFailure ( TestDescription test, String trace)

当原子测试标记其假定条件为 false 时调用

default void testAssumptionFailure ( TestDescription test, FailureDescription failure)

当原子测试标记其假定条件为 false 时调用

default void testEnded ( TestDescription test, long endTime, testMetrics) testEnded ( TestDescription test, long endTime, testMetrics)

ERROR(/#testEnded(com.android.tradefed.result.TestDescription,Map))的替代方案,我们可以直接指定结束时间。

default void testEnded ( TestDescription test, testMetrics) testEnded ( TestDescription test, testMetrics)

报告单个测试用例的执行结束。

default void testFailed ( TestDescription test, FailureDescription failure)

报告单个测试用例的失败。

default void testFailed ( TestDescription test, String trace)

报告单个测试用例的失败。

default void testIgnored ( TestDescription test)

当测试不会运行时调用,通常是因为测试方法用 org.junit.Ignore 注解。

default void testRunEnded (long elapsedTimeMillis, runMetrics) testRunEnded (long elapsedTimeMillis, runMetrics)

报告测试运行结束。

default void testRunFailed ( FailureDescription failure)

报告测试运行由于FailureDescription描述的故障而未能完成。

default void testRunFailed (String errorMessage)

报告测试运行由于致命错误而未能完成。

default void testRunStarted (String runName, int testCount, int attemptNumber)

报告测试运行的开始。

default void testRunStarted (String runName, int testCount)

报告测试运行的开始。

default void testRunStarted (String runName, int testCount, int attemptNumber, long startTime)

报告测试运行的开始。

default void testRunStopped (long elapsedTime)

由于用户请求,报告测试运行在完成之前停止。

default void testSkipped ( TestDescription test, SkipReason reason)

当测试因通常意外的原因而被跳过且未执行时调用。

default void testStarted ( TestDescription test, long startTime)

testStarted(com.android.tradefed.result.TestDescription)的替代方案,其中我们还指定测试开始时间,并结合ERROR(/#testEnded(com.android.tradefed.result.TestDescription,long,Map))进行准确测量。

default void testStarted ( TestDescription test)

报告单个测试用例的开始。

公共方法

测试假设失败

public void testAssumptionFailure (TestDescription test, 
                String trace)

当原子测试标记其假定条件为 false 时调用

参数
test TestDescription :标识测试

trace String : 失败的堆栈跟踪

测试假设失败

public void testAssumptionFailure (TestDescription test, 
                FailureDescription failure)

当原子测试标记其假定条件为 false 时调用

参数
test TestDescription :标识测试

failure FailureDescription :描述故障及其上下文的FailureDescription

测试结束

public void testEnded (TestDescription test, 
                long endTime, 
                 testMetrics)

ERROR(/#testEnded(com.android.tradefed.result.TestDescription,Map))的替代方案,我们可以直接指定结束时间。与testStarted(com.android.tradefed.result.TestDescription, long)结合使用以进行准确测量。

参数
test TestDescription :标识测试

endTime long :测试结束的时间,通过System.currentTimeMillis()测量

testMetrics :发出的指标的ERROR(/Map)

测试结束

public void testEnded (TestDescription test, 
                 testMetrics)

报告单个测试用例的执行结束。

如果未调用testFailed(TestDescription, FailureDescription) ,则此测试通过。还返回测试用例执行期间可能发出的任何键/值指标。

参数
test TestDescription :标识测试

testMetrics :发出的指标的ERROR(/Map)

测试失败

public void testFailed (TestDescription test, 
                FailureDescription failure)

报告单个测试用例的失败。

将在 testStarted 和 testEnded 之间调用。

参数
test TestDescription :标识测试

failure FailureDescription :描述故障及其上下文的FailureDescription

测试失败

public void testFailed (TestDescription test, 
                String trace)

报告单个测试用例的失败。

将在 testStarted 和 testEnded 之间调用。

参数
test TestDescription :标识测试

trace String : 失败的堆栈跟踪

测试被忽略

public void testIgnored (TestDescription test)

当测试不会运行时调用,通常是因为测试方法用 org.junit.Ignore 注解。

参数
test TestDescription :标识测试

测试运行结束

public void testRunEnded (long elapsedTimeMillis, 
                 runMetrics)

报告测试运行结束。 FIXME:我们不能有两个不同类型的 Map<> 接口,所以我们必须在这里使用 HashMap。

参数
elapsedTimeMillis long :设备报告的经过时间,以毫秒为单位

runMetrics :使用Metric测试运行结束时报告的键值对。

测试运行失败

public void testRunFailed (FailureDescription failure)

报告测试运行由于FailureDescription描述的故障而未能完成。

参数
failure FailureDescription :描述故障及其上下文的FailureDescription

测试运行失败

public void testRunFailed (String errorMessage)

报告测试运行由于致命错误而未能完成。

参数
errorMessage String :描述运行失败原因的String

测试运行开始

public void testRunStarted (String runName, 
                int testCount, 
                int attemptNumber)

报告测试运行的开始。

参数
runName String : 测试运行名称

testCount int : 测试运行中的测试总数

attemptNumber int :订单号,标识同一 runName 多次运行的不同尝试。 attemptsNumber 是从 0 开始索引的,并且每次新的运行发生时都应该递增。例如,一个测试被粒度重试 3 次,它应该在同一 runName 下总共运行 4 次,并且 attemptsNumber 从 0 到 3。

测试运行开始

public void testRunStarted (String runName, 
                int testCount)

报告测试运行的开始。

参数
runName String : 测试运行名称

testCount int : 测试运行中的测试总数

测试运行开始

public void testRunStarted (String runName, 
                int testCount, 
                int attemptNumber, 
                long startTime)

报告测试运行的开始。

参数
runName String : 测试运行名称

testCount int : 测试运行中的测试总数

attemptNumber int :订单号,标识同一 runName 多次运行的不同尝试。 attemptsNumber 是从 0 开始索引的,并且每次新的运行发生时都应该递增。例如,一个测试被粒度重试 3 次,它应该在同一 runName 下总共运行 4 次,并且 attemptsNumber 从 0 到 3。

startTime long :运行开始的时间,通过System.currentTimeMillis()测量

测试运行停止

public void testRunStopped (long elapsedTime)

由于用户请求,报告测试运行在完成之前停止。

TODO:当前未使用,考虑删除

参数
elapsedTime long :设备报告的经过时间,以毫秒为单位

测试跳过

public void testSkipped (TestDescription test, 
                SkipReason reason)

当测试因通常意外的原因而被跳过且未执行时调用。将尝试重试这些测试以尝试正确执行。

参数
test TestDescription :标识测试

reason SkipReason : SkipReason

测试开始

public void testStarted (TestDescription test, 
                long startTime)

testStarted(com.android.tradefed.result.TestDescription)的替代方案,其中我们还指定测试开始时间,并结合ERROR(/#testEnded(com.android.tradefed.result.TestDescription,long,Map))进行准确测量。

参数
test TestDescription :标识测试

startTime long :测试开始的时间,通过System.currentTimeMillis()测量

测试开始

public void testStarted (TestDescription test)

报告单个测试用例的开始。较旧的接口,应尽可能使用testStarted(com.android.tradefed.result.TestDescription)

参数
test TestDescription :标识测试