android studio 如何进行单元测试
android studio 如何单元测试
1 新建一个测试类Test,再写一个demoTest()测试方法
public class Test extends InstrumentationTestCase {
public void demoTest(){
assertEquals(1,1);
}
}2 右击鼠标,然后选中运行,点击Test按钮

3 运行结果

很奇怪运行结果居然没有成功,网上翻了一些资料才查明了原因:测试类中的方法名必须要以test开头才行
4 把方法名改成test001后,再次运行,查看结果

5 如何获取context对象进行测试
public class Test extends InstrumentationTestCase {
public void test001(){
Context context = getInstrumentation().getContext();
Toast.makeText(context,"测试成功",Toast.LENGTH_LONG);
Assert.assertEquals(1,1);
}
}
相关推荐
蛰脚踝的天蝎 2020-11-10
Cocolada 2020-11-12
TuxedoLinux 2020-09-11
snowphy 2020-08-19
83540690 2020-08-16
lustdevil 2020-08-03
83417807 2020-07-19
张文倩数据库学生 2020-07-19
bobljm 2020-07-07
83417807 2020-06-28
86427019 2020-06-28
86427019 2020-06-25
zhengzf0 2020-06-21
tobecrazy 2020-06-16
宿命java 2020-06-15
83417807 2020-06-15
84284855 2020-06-11