用Robolectric对GPS功能进行单元测试时应该注解什么?
What should I annotate when I unit test the GPS function with Robolectric?
我指的是以下网站 http://googletesting.blogspot.ca/2010/12/test-sizes.html。有人提到如果我们的测试方法正在访问网络功能,我们应该注释 @LargeTest
。我正在使用 Roboloectric
进行单元测试。
我的方法使用 shadowLocationManager
来模拟 GPS 位置。我不确定我应该为 GPSTest
注释什么。我应该选择 @Test
还是选择 @LargeTest
。我刚开始用 Robolectric
学习单元测试。到目前为止,我一直在对我的所有测试使用 @Test
注释,但我没有遇到任何问题。有人可以建议我 Robolectric
.
应遵循的正确注释吗
编辑:@SmallTest
、@MediumTest
、@LargeTest
注释在我的 GPS 测试中失败,@Test
通过了测试。这些注释对 Robolectric
不起作用吗?如果是这样,那么我如何用不同的注释标记我的测试?
如果你想看看我的测试方法,请看下面的代码:
@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);
}
底线:(我想我现在可以期待投票了……感到自豪 :D :P)
你是对的,这些注释不适用于 Robolectric。
它们在使用在设备上运行测试的 Android InstrumentationTestRunner 时很有用。
Robolectric 在 JVM 上运行测试,完全不同。
我指的是以下网站 http://googletesting.blogspot.ca/2010/12/test-sizes.html。有人提到如果我们的测试方法正在访问网络功能,我们应该注释 @LargeTest
。我正在使用 Roboloectric
进行单元测试。
我的方法使用 shadowLocationManager
来模拟 GPS 位置。我不确定我应该为 GPSTest
注释什么。我应该选择 @Test
还是选择 @LargeTest
。我刚开始用 Robolectric
学习单元测试。到目前为止,我一直在对我的所有测试使用 @Test
注释,但我没有遇到任何问题。有人可以建议我 Robolectric
.
编辑:@SmallTest
、@MediumTest
、@LargeTest
注释在我的 GPS 测试中失败,@Test
通过了测试。这些注释对 Robolectric
不起作用吗?如果是这样,那么我如何用不同的注释标记我的测试?
如果你想看看我的测试方法,请看下面的代码:
@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);
}
底线:(我想我现在可以期待投票了……感到自豪 :D :P)
你是对的,这些注释不适用于 Robolectric。
它们在使用在设备上运行测试的 Android InstrumentationTestRunner 时很有用。
Robolectric 在 JVM 上运行测试,完全不同。