DeviceTestCase
public
class
DeviceTestCase
extends MetricTestCase
implements
IDeviceTest,
IRemoteTest,
ITestAnnotationFilterReceiver,
ITestCollector,
ITestFilterReceiver
| java.lang.Object | ||||
| ↳ | junit.framework.Assert | |||
| ↳ | junit.framework.TestCase | |||
| ↳ | com.android.tradefed.testtype.MetricTestCase | |||
| ↳ | com.android.tradefed.testtype.DeviceTestCase | |||
提供 IRemoteTest 和 IDeviceTest 服务的辅助 JUnit 测试用例。
如果您想实现遵循 JUnit 测试定义模式的测试,同时仍能完全支持其他 Tradefed 功能(例如 Option),这会非常有用
摘要
字段 | |
|---|---|
protected
Set<String> |
mExcludeAnnotation
要运行的测试的排除注释 |
protected
Set<String> |
mExcludeFilters
要运行的测试名称的排除过滤条件 |
protected
Set<String> |
mIncludeAnnotation
要运行的测试的包含注释 |
protected
Set<String> |
mIncludeFilters
要运行的测试名称的包含过滤条件 |
公共构造函数 | |
|---|---|
DeviceTestCase()
|
|
DeviceTestCase(String name)
|
|
公共方法 | |
|---|---|
void
|
addAllExcludeAnnotation(Set<String> notAnnotations)
添加了 |
void
|
addAllExcludeFilters(Set<String> filters)
添加用于指定要排除哪些测试的过滤条件 |
void
|
addAllIncludeAnnotation(Set<String> annotations)
添加一个注解 |
void
|
addAllIncludeFilters(Set<String> filters)
添加用于指定要包含哪些测试的过滤条件 |
void
|
addExcludeAnnotation(String notAnnotation)
添加了一个注解,用于排除标记了该注解的测试。 |
void
|
addExcludeFilter(String filter)
添加用于指定要排除哪些测试的过滤条件。 |
void
|
addIncludeAnnotation(String annotation)
添加一个注解,如果测试标记了该注解,则包含该测试。 |
void
|
addIncludeFilter(String filter)
添加用于指定要包含哪些测试的过滤条件。 |
void
|
clearExcludeAnnotations()
删除当前跟踪的所有排除注释。 |
void
|
clearExcludeFilters()
删除当前跟踪的所有排除过滤条件。 |
void
|
clearIncludeAnnotations()
删除当前跟踪的所有 include 注释。 |
void
|
clearIncludeFilters()
删除当前跟踪的所有包含过滤条件。 |
int
|
countTestCases()
|
ITestDevice
|
getDevice()
获取被测设备。 |
Set<String>
|
getExcludeAnnotations()
返回要排除的注释的当前 |
Set<String>
|
getExcludeFilters()
返回当前的排除过滤条件 |
Set<String>
|
getIncludeAnnotations()
返回要包含的注释的当前 |
Set<String>
|
getIncludeFilters()
返回当前的包含过滤条件 |
void
|
run(TestResult result)
替换父方法以在要运行的测试方法为 null 时运行所有测试方法。 |
void
|
run(TestInformation testInfo, ITestInvocationListener listener)
运行测试,并将结果报告给监听器。 |
void
|
setCollectTestsOnly(boolean shouldCollectTest)
启用或停用测试收集模式 |
void
|
setDevice(ITestDevice device)
注入被测设备。 |
字段
mExcludeAnnotation
protected Set<String> mExcludeAnnotation
要运行的测试的排除注释
mExcludeFilters
protected Set<String> mExcludeFilters
要运行的测试名称的排除过滤条件
mIncludeAnnotation
protected Set<String> mIncludeAnnotation
要运行的测试的 include 注释
mIncludeFilters
protected Set<String> mIncludeFilters
要运行的测试名称的包含过滤条件
公共构造函数
DeviceTestCase
public DeviceTestCase ()
DeviceTestCase
public DeviceTestCase (String name)
| 参数 | |
|---|---|
name |
String |
公共方法
addAllExcludeAnnotation
public void addAllExcludeAnnotation (Set<String> notAnnotations)
添加了 Set 注解,如果测试标记了该注解,则排除相应测试。
| 参数 | |
|---|---|
notAnnotations |
Set |
addAllExcludeFilters
public void addAllExcludeFilters (Set<String> filters)
添加用于指定要排除哪些测试的过滤条件Set。
| 参数 | |
|---|---|
filters |
Set |
addAllIncludeAnnotation
public void addAllIncludeAnnotation (Set<String> annotations)
添加一个注解 Set 列表,如果测试标记了这些注解,则包含这些测试。
| 参数 | |
|---|---|
annotations |
Set |
addAllIncludeFilters
public void addAllIncludeFilters (Set<String> filters)
添加用于指定要包含哪些测试的过滤条件Set。
| 参数 | |
|---|---|
filters |
Set |
addExcludeAnnotation
public void addExcludeAnnotation (String notAnnotation)
添加了一个注解,用于排除标记了该注解的测试。
| 参数 | |
|---|---|
notAnnotation |
String |
addExcludeFilter
public void addExcludeFilter (String filter)
添加用于指定要排除哪些测试的过滤条件。
| 参数 | |
|---|---|
filter |
String |
addIncludeAnnotation
public void addIncludeAnnotation (String annotation)
添加了注解,用于指定如果测试标记了该注解,则包含该测试。
| 参数 | |
|---|---|
annotation |
String |
addIncludeFilter
public void addIncludeFilter (String filter)
添加用于指定要包含哪些测试的过滤条件。
| 参数 | |
|---|---|
filter |
String |
clearExcludeAnnotations
public void clearExcludeAnnotations ()
删除当前跟踪的所有排除注释。
clearExcludeFilters
public void clearExcludeFilters ()
删除当前跟踪的所有排除过滤条件。
clearIncludeAnnotations
public void clearIncludeAnnotations ()
删除当前跟踪的所有包含注释。
clearIncludeFilters
public void clearIncludeFilters ()
删除当前跟踪的所有包含过滤条件。
countTestCases
public int countTestCases ()
| 返回 | |
|---|---|
int |
|
run
public void run (TestResult result)
替换父方法以在要运行的测试方法为 null 时运行所有测试方法。
JUnit 框架仅支持通过将 TestCase 封装在 TestSuite 中来运行其中的所有测试。遗憾的是,借助此机制,调用方无法控制其自身测试用例的生命周期,这使得无法执行诸如让 Tradefed 配置框架将选项注入到测试用例之类的操作。
| 参数 | |
|---|---|
result |
TestResult |
run
public void run (TestInformation testInfo, ITestInvocationListener listener)
运行测试,并将结果报告给监听器。
| 参数 | |
|---|---|
testInfo |
TestInformation:包含用于运行测试的实用信息的 TestInformation 对象。 |
listener |
ITestInvocationListener:测试结果的 ITestInvocationListener |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
setCollectTestsOnly
public void setCollectTestsOnly (boolean shouldCollectTest)
启用或停用测试收集模式