Bha*_*war 17 testing gps android android-testing
你如何测试Android中的 GPS应用程序?我们可以使用Android模拟器进行测试吗?
Jef*_*elt 27
是.
如果使用Eclipse ADT插件进行开发,请在启动模拟器后打开DDMS透视图并查找"模拟器控件"视图.有一个位置控制部分,允许您发送固定的经纬度坐标,或GPX(GPS交换格式)或KML(锁孔标记语言)文件,如果您想定期发送多个坐标(模拟特定路线的旅行) .
或者,您可以简单地telnet到模拟器并使用命令行中的geo命令,该命令行支持固定的纬度和经度坐标以及NMEA数据句子:
telnet localhost 5554
geo fix -82.411629 28.054553
geo nmea $GPGGA,001431.092,0118.2653,N,10351.1359,E,0,00,,-19.6,M,4.1,M,,0000*5B
Run Code Online (Sandbox Code Playgroud)
Mal*_*lox 15
也许你想使用单元测试,所以你可以试试这个:
public class GPSPollingServiceTest extends AndroidTestCase {
private LocationManager locationManager;
public void testGPS() {
LocationManager locationManager = (LocationManager) this.getContext().getSystemService(Context.LOCATION_SERVICE);
locationManager.addTestProvider("Test", false, false, false, false, false, false, false, Criteria.POWER_LOW, Criteria.ACCURACY_FINE);
locationManager.setTestProviderEnabled("Test", true);
// Set up your test
Location location = new Location("Test");
location.setLatitude(10.0);
location.setLongitude(20.0);
locationManager.setTestProviderLocation("Test", location);
// Check if your listener reacted the right way
locationManager.removeTestProvider("Test");
}
}
Run Code Online (Sandbox Code Playgroud)
为此,您还需要AndroidManifest.xml的必需权限:
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24734 次 |
| 最近记录: |