public class InstrumentationTestCase
extends TestCase
| java.lang.Object | |||
| junit.framework.Assert | |||
| junit.framework.TestCase | |||
| android.test.InstrumentationTestCase | |||
|
ActivityTestCase,
ProviderTestCase<T extends
ContentProvider>,
SingleLaunchActivityTestCase<T extends
Activity>,
SyncBaseInstrumentation
|
|
ActivityInstrumentationTestCase<T extends
Activity>,
ActivityInstrumentationTestCase2<T extends
Activity>,
ActivityUnitTestCase<T extends
Activity>
|
此类在API级别24中已被弃用。
改为使用InstrumentationRegistry 。 应使用Android Testing Support Library编写新的测试。
一个可以访问 Instrumentation 。
Public constructors |
|
|---|---|
InstrumentationTestCase() |
|
公共方法(Public methods) |
|
|---|---|
Instrumentation |
getInstrumentation() 继承者可以使用它来访问这些工具。 |
void |
injectInsrumentation(Instrumentation instrumentation) 此方法在API级别5中已弃用。拼写错误, |
void |
injectInstrumentation(Instrumentation instrumentation) 将测试仪器插入此测试案例。 |
final <T extends Activity> T |
launchActivity(String pkg, Class<T> activityCls, Bundle extras) 启动活动的实用程序方法。 |
final <T extends Activity> T |
launchActivityWithIntent(String pkg, Class<T> activityCls, Intent intent) 使用特定意图启动活动的实用程序方法。 |
void |
runTestOnUiThread(Runnable r) Helper用于在UI线程上运行测试的各个部分。 |
void |
sendKeys(String keysSequence) 通过仪器发送一系列关键事件并等待空闲。 |
void |
sendKeys(int... keys) 通过仪器发送一系列关键事件并等待空闲。 |
void |
sendRepeatedKeys(int... keys) 通过仪器发送一系列关键事件并等待空闲。 |
Protected methods |
|
|---|---|
void |
runTest() 运行当前的单元测试。 |
void |
tearDown() 在开始下一个测试之前,确保清理所有资源并收集垃圾。 |
继承方法(Inherited methods) |
|
|---|---|
junit.framework.TestCase
|
|
junit.framework.Assert
|
|
java.lang.Object
|
|
junit.framework.Test
|
|
Instrumentation getInstrumentation ()
继承者可以使用它来访问这些工具。
| 返回(Returns) | |
|---|---|
Instrumentation |
instrumentation |
void injectInsrumentation (Instrumentation instrumentation)
此方法在API级别5中已被弃用。
拼写错误, injectInstrumentation(android.app.Instrumentation)改为使用injectInstrumentation(android.app.Instrumentation) 。
将测试仪器插入此测试案例。 在测试设置期间,该方法由测试运行器调用。
| 参数(Parameters) | |
|---|---|
instrumentation |
Instrumentation: the instrumentation to use with this instance |
void injectInstrumentation (Instrumentation instrumentation)
将测试仪器插入此测试案例。 在测试设置期间,该方法由测试运行器调用。
| 参数(Parameters) | |
|---|---|
instrumentation |
Instrumentation: the instrumentation to use with this instance |
T launchActivity (String pkg, Class<T> activityCls, Bundle extras)
启动活动的实用程序方法。
用于启动活动的 Intent是:action = ACTION_MAIN extras = null,除非在此处提供了自定义包所有其他字段为空或空。
注意:参数pkg必须引用托管要启动的活动的包的包标识符,这在AndroidManifest.xml文件中指定。 这不一定与java包名称相同。
| 参数(Parameters) | |
|---|---|
pkg |
String: The package hosting the activity to be launched. |
activityCls |
Class: The activity class to launch. |
extras |
Bundle: Optional extra stuff to pass to the activity. |
| 返回(Returns) | |
|---|---|
T |
The activity, or null if non launched. |
T launchActivityWithIntent (String pkg, Class<T> activityCls, Intent intent)
使用特定意图启动活动的实用程序方法。
注意:参数pkg必须引用托管要启动的活动的包的包标识符,这在AndroidManifest.xml文件中指定。 这不一定与java包名称相同。
| 参数(Parameters) | |
|---|---|
pkg |
String: The package hosting the activity to be launched. |
activityCls |
Class: The activity class to launch. |
intent |
Intent: The intent to launch with |
| 返回(Returns) | |
|---|---|
T |
The activity, or null if non launched. |
void runTestOnUiThread (Runnable r)
Helper用于在UI线程上运行测试的各个部分。 请注意,在大多数情况下,使用UiThreadTest注释测试方法会更简单,该方法将在UI线程上运行整个测试方法。 如果您需要切换到UI线程以执行测试,请使用此方法。
| 参数(Parameters) | |
|---|---|
r |
Runnable: runnable containing test code in the run() method |
| 抛出异常(Throws) | |
|---|---|
Throwable |
|
void sendKeys (String keysSequence)
通过仪器发送一系列关键事件并等待空闲。 密钥序列是一个包含KeyEvent中指定的密钥名称的字符串,不带KEYCODE_前缀。 例如:sendKeys(“DPAD_LEFT ABC DPAD_CENTER”)。 每个密钥可以通过使用N *前缀来重复。 例如,要发送两个KEYCODE_DPAD_LEFT,请使用以下命令:sendKeys(“2 * DPAD_LEFT”)。
| 参数(Parameters) | |
|---|---|
keysSequence |
String: The sequence of keys. |
void sendKeys (int... keys)
通过仪器发送一系列关键事件并等待空闲。 例如:sendKeys(KEYCODE_DPAD_LEFT,KEYCODE_DPAD_CENTER)。
| 参数(Parameters) | |
|---|---|
keys |
int: The series of key codes to send through instrumentation. |
void sendRepeatedKeys (int... keys)
通过仪器发送一系列关键事件并等待空闲。 每个密钥代码必须以密钥代码必须发送的次数作为前缀。 例如:sendRepeatedKeys(1,KEYCODE_DPAD_CENTER,2,KEYCODE_DPAD_LEFT)。
| 参数(Parameters) | |
|---|---|
keys |
int: The series of key repeats and codes to send through instrumentation. |
void runTest ()
运行当前的单元测试。 如果单元测试用UiThreadTest标注,则测试在UI线程上运行。
| 抛出异常(Throws) | |
|---|---|
Throwable |
|
void tearDown ()
在开始下一个测试之前,确保清理所有资源并收集垃圾。 覆盖此方法的子类应确保它们在重写方法的末尾调用super.tearDown()。
| 抛出异常(Throws) | |
|---|---|
异常 |
|