赞
踩
AndroidJUnitRunner,Google官方的android单元测试框架之一,适用于 Android 且与 JUnit 4 兼容的测试运行器!测试运行器可以将测试软件包和要测试的应用加载到设备、运行测试并报告测试结果。
此测试运行器的主要功能包括:
要求 Android 2.2(API 级别 8)或更高版本。
JUnit 支持
测试运行器与 JUnit 3 和 JUnit 4(最高版本为 JUnit 4.10)测试兼容。使用时不要混用JUnit 3 和 JUnit 4 测试代码。如果要创建一个 JUnit 4 仪器测试类以在设备或模拟器上运行,则测试类必须以 @RunWith(AndroidJUnit4.class) 注解作为前缀。
如下是一个验证包名的JUnit 4 仪器:
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.yangge.myapplication", appContext.getPackageName());
}
}
访问仪器信息
可以使用 InstrumentationRegistry 类访问与测试运行相关的信息。
如 Instrumentation 对象:
/**
* Returns the instrumentation currently running. Use this to get an {@link Instrumentation}
* into your test.
*
* @throws IllegalStateException if instrumentation hasn&#
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。