设置来自JUnit单元测试的android.location.Location对象的参数
作者:互联网
我正在尝试对接收android.location.Location对象的函数进行单元测试.但是我阻止了,因为我没有可能为Location对象设置参数.
@Test
public void testLocation() {
Location location = new Location("gps");
location.setAccuracy(25F);
location.setTime(5123L);
System.out.println("Accuracy: " + location.getAccuracy());
System.out.println("Time: " + location.getTime());
}
输出:
Accuracy: 0.0
Time: 0
Process finished with exit code 0
定位精度和时间为零,但这些值已在上面的代码中设置.
这不是仪器测试,我正在jvm下将其作为简单的单元测试运行(测试工件:单元测试).
使用JUnit 4.12
解决方法:
添加@RunWith(RobolectricTestRunner.class)之后,它会按预期工作.
标签:locationmanager,unit-testing,junit,android-location,android 来源: https://codeday.me/bug/20191027/1942911.html