1.根据需求创建TestCase类,实现测试用例。此类需继承AndroidTestCase类
public class TestCase extends AndroidTestCase { @Override
protected void setUp() throws Exception {
// TODO Auto-generated method stub
super.setUp();
Log.d("debug", "enter setUp method");
} public void case() {
Log.d("debug", "enter case method");
} @Override
protected void tearDown() throws Exception {
// TODO Auto-generated method stub
super.tearDown();
Log.d("debug", "enter tearDown method");
}
}
2.修改AndroidManifest.xml
(1)在Application TAG 外部(同级)添加instrumentation
<instrumentation android:name="android.test.InstrumentationTestRunner" android:label="Test" android:targetPackage="com.example.test" />
(2)在Application内部添加 uses-library
<uses-library android:name="android.test.runner" />
3.选中case 方法名,右键 Run As --> Android JUnit Test 执行即可