设置来自JUnit单元测试的android.location.Location对象的参数 [英] Set parameters of android.location.Location object from JUnit unit test
问题描述
我正在尝试对接收android.location.Location对象的函数进行单元测试.但是我阻止了,因为我无法为Location对象设置参数.
I'm trying to make unit test for a function which receive android.location.Location object. But i blocked because i don't have possibility to set up parameters for Location object.
@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
位置精度和时间为零,但这些值是在上面的代码中设置的. 这不是一项Intrumentation测试,我将其作为简单的单元测试在jvm下运行(测试工件:单元测试).
Location accuracy and time are zero but the values were set in code above. It's not an Intrumentation test, i'm running it as simple unit test under jvm (Test Artifact: Unit Tests).
使用JUnit 4.12
Using JUnit 4.12
推荐答案
添加@RunWith(RobolectricTestRunner.class)后,它会按预期工作.
After adding @RunWith(RobolectricTestRunner.class) - it works as expected.
这篇关于设置来自JUnit单元测试的android.location.Location对象的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!