jeudi 18 juin 2015

What should I annotate when I unit test the GPS function with Robolectric?

I am referring the following site http://ift.tt/1GSaJCY . There it was mentioned that we should annotate @LargeTest if our test method is accessing the network feature. I am using Roboloectric for unit testing. And my method uses the shadowLocationManager to simulate the GPS location. I am not sure what should I annotate for my GPSTest. Should I go for @Test or go for @LargeTest. I just started learning the unit testing with Robolectric. I been using @Test annotation for all my tests so far and I didn't face a problem. Can someone please suggest me the proper annotation to be followed for Robolectric.

Edit: The @SmallTest,@MediumTest,@LargeTest annotation failed in my GPS Test and @Test passed the test. Are these annotations doesn't work on Robolectric? If so,then how can I mark my tests with different annotations?

If you want to have a look at my test method,please look at the following code:

@Before
public void setUp() {
  mainActivity = new Settings();
  mainActivity=Robolectric.buildActivity(Settings.class).create().get();
}
@Test
public void shouldReturnTheLatestLocation() {
    LocationManager locationManager = (LocationManager)
            Robolectric.application.getSystemService(Context.LOCATION_SERVICE);
    ShadowLocationManager shadowLocationManager = Robolectric.shadowOf(locationManager);
    Location expectedLocation = location(locationManager.NETWORK_PROVIDER, 12.0, 20.0);

    shadowLocationManager.simulateLocation(expectedLocation);

  System.out.print("expected location is "+expectedLocation.getLatitude()+expectedLocation.getLongitude());
    Location actualLocation = mainActivity.latestLocation();
   System.out.print("actual location is "+actualLocation.getLatitude()+actualLocation.getLongitude());
    assertEquals(expectedLocation, actualLocation);
}

Aucun commentaire:

Enregistrer un commentaire