原文链接:https://www.jianshu.com/p/0db8381ca480
参考:https://www.jianshu.com/p/37207d56331f
Android测试基于JUnit,创建项目后,AndroidStudio默认会帮我们创建两个测试类:
上面ExampleUnitTest用于测试不需要Android相关组件的方法,而ExampleInstrumentedTest则是测试一些需要基于Android组件的方法,例如需要页面,数据,服务什么的!
1.ExampleUnitTest:
例如:你只想测试一下两个数的计算是否正确,可以打印计算后的结果:
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
@Test
public void computer() throws Exception {
double a = 1.89d;
double b = 0.9d;
System.out.print(ComputationUtil.mul(a, b));
}
}
测试结果
网友评论