Loading

AndroidTestCase简单使用

1.根据需求创建TestCase类,实现测试用例。此类需继承AndroidTestCase类

 1 public class TestCase extends AndroidTestCase {
 2 
 3     @Override
 4     protected void setUp() throws Exception {
 5         // TODO Auto-generated method stub
 6         super.setUp();
 7         Log.d("debug", "enter setUp method");
 8     }
 9     
10     public void case() {
11                 Log.d("debug", "enter case method");
12     }
13 
14     @Override
15     protected void tearDown() throws Exception {
16         // TODO Auto-generated method stub
17         super.tearDown();
18         Log.d("debug", "enter tearDown method");
19     }
20 }

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 执行即可

posted @ 2016-01-15 10:49  多啦宝宝  阅读(3703)  评论(0编辑  收藏  举报