新建ANDROID TEST项目
ECLIPSE右键-->new -->Other-->Android -->Android Test Project-->选择你要测试的项目
简单测试代码
然后右键运行TestAll-->Run As-->JUnit Test
ECLIPSE右键-->new -->Other-->Android -->Android Test Project-->选择你要测试的项目
简单测试代码
public class SampleCalculator {
public int add(int augend, int addend) {
return augend + addend;
}
public int subtration(int minuend, int subtrahend) {
return minuend - subtrahend;
}
}
public class TestSample extends TestCase {
private int a;
private int b;
private int r1, r2;
@Override
protected void setUp() throws Exception {
super.setUp();
a = 50;
b = 20;
r1 = 70;
r2 = 30;
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
//test打头的方法会被自动测试
public void testAdd() {
SampleCalculator calculator = new SampleCalculator();
int result = calculator.add(a, b);
assertEquals(r1, result);
}
}
public class TestAll {
public static Test suite() {
TestSuite suite = new TestSuite("TestSuite Test");
//这里可以添加不同的测试类
suite.addTestSuite(TestSample.class);
return suite;
}
}
然后右键运行TestAll-->Run As-->JUnit Test