1.在清单文件中manifest节点下配置如下节点
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.itheima.junit" />
2.在清单文件中application节点下配置如下节点
<uses-library
android:name="android.test.runner"/>
3.编写业务逻辑类
package com.itheima.junit.service;
public class UserService {
public int add(int x, int y) {
return x + y;
}
}
4.编写单元测试类,该类继承 AndroidTestCase
package com.itheima.junit.test;
import android.test.AndroidTestCase;
import com.itheima.junit.service.UserService;
public class TestUserService extends AndroidTestCase {
public void testAdd() throws Exception {
UserService us = new UserService();
int result = us.add(3, 5);
assertEquals(8, result);
}
}