Heim > Fragen und Antworten > Hauptteil
除了在useAppContext()
里的方法有效果?
在这个类的其他方法测试
@Test
public void testSOmething() throws Exception {
assertEquals("a", "a");
}
运行结果是
$ adb shell am instrument -w -r -e debug false -e class com.aa.safe.locked.ExampleInstrumentedTest#testSOmething com.aa.safe.locked.test/android.test.InstrumentationTestRunner
Client not ready yet..
Started running tests
Test running failed: Unable to find instrumentation info for: ComponentInfo{com.aa.safe.locked.test/android.test.InstrumentationTestRunner}
Empty test suite.
而在这个类自带的方法中测试
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
// Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("a", "a");
// assertEquals("com.aa.safe.locked", appContext.getPackageName());
}
结果是成功
$ adb shell am instrument -w -r -e debug false -e class com.aa.safe.locked.ExampleInstrumentedTest#useAppContext com.aa.safe.locked.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests
Tests ran to completion.
我建立了一个类继承AndroidTestCase
, 然后在清单文件里进行配置,但是在配置的过程中发现
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.aa.safe.locked" >
</instrumentation>
在targetPackage这里,包名提示是错误的,即使它和我的
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aa.safe.locked">
package是一样的,也提示错误.
### 请教一下 studio 单元测试应该怎么操作?