Set parameters of android.location.Location object from JUnit unit test

好久不见. 提交于 2019-12-10 19:03:45

问题


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());
}

Output:

Accuracy: 0.0
Time: 0

Process finished with exit code 0

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).

Using JUnit 4.12


回答1:


After adding @RunWith(RobolectricTestRunner.class) - it works as expected.



来源:https://stackoverflow.com/questions/35987519/set-parameters-of-android-location-location-object-from-junit-unit-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!