ModuleListener
public
class
ModuleListener
extends CollectingTestListener
| java.lang.Object | ||
| ↳ | com.android.tradefed.result.CollectingTestListener | |
| ↳ | com.android.tradefed.testtype.suite.ModuleListener | |
附加到每个模块的每个 IRemoteTest 的监听器,用于收集结果列表。
摘要
公共构造函数 | |
|---|---|
ModuleListener(ITestInvocationListener listener, IInvocationContext moduleContext)
构造函数。 |
|
公共方法 | |
|---|---|
boolean
|
hasLastAttemptFailed()
返回监听器上次重试会话是否失败。 |
void
|
logAssociation(String dataName, LogFile logFile)
在某些情况下,日志必须与测试用例紧密关联,但无法在直接 |
void
|
setAttemptIsolation(CurrentInvocation.IsolationGrade isolation)
设置是否应将尝试报告为隔离。 |
void
|
setCollectTestsOnly(boolean collectTestsOnly)
设置是否仅收集测试。 |
void
|
setMarkTestsSkipped(boolean skip)
是否将所有测试用例标记为跳过。 |
void
|
setTestMappingSources(List<String> testMappingSources)
设置将插入到指标中的测试映射来源。 |
void
|
setUseModuleResultsForwarder(boolean useModuleResultsForwarder)
|
void
|
testAssumptionFailure(TestDescription test, String trace)
当原子测试标记其假设的条件为 false 时调用 |
void
|
testAssumptionFailure(TestDescription test, FailureDescription failure)
当原子测试标记其假设的条件为 false 时调用 |
void
|
testEnded(TestDescription test, HashMap<String, MetricMeasurement.Metric> testMetrics)
报告单个测试用例的执行结束时间。 |
void
|
testEnded(TestDescription test, long endTime, HashMap<String, MetricMeasurement.Metric> testMetrics)
|
void
|
testFailed(TestDescription test, FailureDescription failure)
报告单个测试用例的失败情况。 |
void
|
testFailed(TestDescription test, String trace)
报告单个测试用例的失败情况。 |
void
|
testIgnored(TestDescription test)
当测试不会运行时(通常是因为测试方法使用 org.junit.Ignore 注释进行了注释)调用。 |
void
|
testLog(String dataName, LogDataType dataType, InputStreamSource dataStream)
|
void
|
testLogSaved(String dataName, LogDataType dataType, InputStreamSource dataStream, LogFile logFile)
|
void
|
testRunEnded(long elapsedTime, HashMap<String, MetricMeasurement.Metric> runMetrics)
报告测试运行结束。 |
void
|
testRunFailed(FailureDescription failure)
报告测试运行因 |
void
|
testRunFailed(String errorMessage)
由于出现严重错误,报告测试运行未能完成。 |
void
|
testRunStarted(String name, int numTests, int attemptNumber)
报告测试运行的开始。 |
void
|
testRunStarted(String name, int numTests, int attemptNumber, long startTime)
报告测试运行的开始。 |
void
|
testSkipped(TestDescription test, SkipReason reason)
当测试因通常不预期的原因而被跳过且未执行时调用。 |
void
|
testStarted(TestDescription test, long startTime)
|
公共构造函数
ModuleListener
public ModuleListener (ITestInvocationListener listener, IInvocationContext moduleContext)
构造函数。
| 参数 | |
|---|---|
listener |
ITestInvocationListener |
moduleContext |
IInvocationContext |
公共方法
hasLastAttemptFailed
public boolean hasLastAttemptFailed ()
返回监听器上次重试会话是否失败。
| 返回 | |
|---|---|
boolean |
|
logAssociation
public void logAssociation (String dataName,
LogFile logFile)在某些情况下,日志必须与测试用例紧密关联,但无法在直接 testLogSaved(String,LogDataType,InputStreamSource,LogFile) 回调中实现这一点。因此,此回调允许显式提供强关联。
| 参数 | |
|---|---|
dataName |
String:数据的名称 |
logFile |
LogFile:之前记录的 LogFile,应与测试用例相关联。 |
setAttemptIsolation
public void setAttemptIsolation (CurrentInvocation.IsolationGrade isolation)
设置是否应将尝试报告为隔离。
| 参数 | |
|---|---|
isolation |
CurrentInvocation.IsolationGrade |
setCollectTestsOnly
public void setCollectTestsOnly (boolean collectTestsOnly)
设置是否仅收集测试。
| 参数 | |
|---|---|
collectTestsOnly |
boolean |
setMarkTestsSkipped
public void setMarkTestsSkipped (boolean skip)
是否将所有测试用例标记为跳过。
| 参数 | |
|---|---|
skip |
boolean |
setTestMappingSources
public void setTestMappingSources (List<String> testMappingSources)
设置将插入到指标中的测试映射来源。
| 参数 | |
|---|---|
testMappingSources |
List |
setUseModuleResultsForwarder
public void setUseModuleResultsForwarder (boolean useModuleResultsForwarder)
| 参数 | |
|---|---|
useModuleResultsForwarder |
boolean |
testAssumptionFailure
public void testAssumptionFailure (TestDescription test, String trace)
当原子测试标记其假设的条件为 false 时调用
| 参数 | |
|---|---|
test |
TestDescription:标识测试 |
trace |
String:失败的堆栈轨迹 |
testAssumptionFailure
public void testAssumptionFailure (TestDescription test, FailureDescription failure)
当原子测试标记其假设的条件为 false 时调用
| 参数 | |
|---|---|
test |
TestDescription:标识测试 |
failure |
FailureDescription:描述失败及其上下文的 FailureDescription。 |
testEnded
public void testEnded (TestDescription test, HashMap<String, MetricMeasurement.Metric> testMetrics)
报告单个测试用例的执行结束时间。
如果未调用 testFailed(TestDescription, FailureDescription),则此测试通过。还会返回测试用例执行期间可能发出的任何键值指标。
| 参数 | |
|---|---|
test |
TestDescription:标识测试 |
testMetrics |
HashMap:所发出指标的 Map |
testEnded
public void testEnded (TestDescription test, long endTime, HashMap<String, MetricMeasurement.Metric> testMetrics)
testEnded(TestDescription,Map) 的替代方案,可直接指定结束时间。与 testStarted(TestDescription,long) 结合使用,可实现精确衡量。
| 参数 | |
|---|---|
test |
TestDescription:标识测试 |
endTime |
long:测试结束时间,通过 System.currentTimeMillis() 测量 |
testMetrics |
HashMap:所发出指标的 Map |
testFailed
public void testFailed (TestDescription test, FailureDescription failure)
报告单个测试用例的失败。
将在 testStarted 和 testEnded 之间调用。
| 参数 | |
|---|---|
test |
TestDescription:标识测试 |
failure |
FailureDescription:描述失败及其上下文的 FailureDescription。 |
testFailed
public void testFailed (TestDescription test, String trace)
报告单个测试用例的失败。
将在 testStarted 和 testEnded 之间调用。
| 参数 | |
|---|---|
test |
TestDescription:标识测试 |
trace |
String:失败的堆栈轨迹 |
testIgnored
public void testIgnored (TestDescription test)
当测试不会运行时调用,通常是因为测试方法使用 org.junit.Ignore 注释。
| 参数 | |
|---|---|
test |
TestDescription:标识测试 |
testLog
public void testLog (String dataName,
LogDataType dataType,
InputStreamSource dataStream)| 参数 | |
|---|---|
dataName |
String |
dataType |
LogDataType |
dataStream |
InputStreamSource |
testLogSaved
public void testLogSaved (String dataName,
LogDataType dataType,
InputStreamSource dataStream,
LogFile logFile)| 参数 | |
|---|---|
dataName |
String |
dataType |
LogDataType |
dataStream |
InputStreamSource |
logFile |
LogFile |
testRunEnded
public void testRunEnded (long elapsedTime,
HashMap<String, MetricMeasurement.Metric> runMetrics)报告测试运行结束。FIXME:我们不能有两个具有不同类型的 Map<> 接口,因此我们必须在此处使用 HashMap。
| 参数 | |
|---|---|
elapsedTime |
long:设备报告的已用时间,以毫秒为单位 |
runMetrics |
HashMap:在测试运行结束时通过 Metric 报告的键值对。 |
testRunFailed
public void testRunFailed (FailureDescription failure)
报告测试运行因 FailureDescription 所述的失败而未能完成。
| 参数 | |
|---|---|
failure |
FailureDescription:描述失败及其上下文的 FailureDescription。 |
testRunFailed
public void testRunFailed (String errorMessage)
由于出现严重错误,报告测试运行未能完成。
| 参数 | |
|---|---|
errorMessage |
String:String,用于描述运行失败的原因。 |
testRunStarted
public void testRunStarted (String name,
int numTests,
int attemptNumber)报告测试运行的开始。
| 参数 | |
|---|---|
name |
String:测试运行名称 |
numTests |
int:测试运行中的测试总数 |
attemptNumber |
int:用于标识多次运行的同一 runName 的不同尝试的订单号。attemptNumber 的索引从 0 开始,每次新运行时都应递增。例如,如果某测试细粒度重试 3 次,则在同一 runName 下应总共有 4 次运行,且 attemptNumber 从 0 到 3。 |
testRunStarted
public void testRunStarted (String name,
int numTests,
int attemptNumber,
long startTime)报告测试运行的开始。
| 参数 | |
|---|---|
name |
String:测试运行名称 |
numTests |
int:测试运行中的测试总数 |
attemptNumber |
int:用于标识多次运行的同一 runName 的不同尝试的订单号。attemptNumber 从 0 开始,每次新运行时都会递增。例如,如果某个测试进行了 3 次精细重试,则在同一 runName 下,该测试总共应运行 4 次,且 attemptNumber 为 0 到 3。 |
startTime |
long:运行开始时间,通过 System.currentTimeMillis() 测量 |
testSkipped
public void testSkipped (TestDescription test, SkipReason reason)
当测试因通常不预期的原因而被跳过且未执行时调用。 系统将尝试重试这些测试,以尝试获得正确的执行结果。
| 参数 | |
|---|---|
test |
TestDescription:标识测试 |
reason |
SkipReason:SkipReason |
testStarted
public void testStarted (TestDescription test, long startTime)
testStarted(TestDescription) 的替代方案,我们还指定了测试开始时间,并与 testEnded(TestDescription,long,Map) 结合使用以实现精确衡量。
| 参数 | |
|---|---|
test |
TestDescription:标识测试 |
startTime |
long:测试开始时间,通过 System.currentTimeMillis() 测量 |