有没有人能够在Android Studio中运行测试(从GUI而不是终端),我无法从GUI运行测试.
每次我尝试通过GUI运行测试时,我只会收到以下消息:

我可以使用以下命令从终端运行测试:
./gradlew connectedAndroidTest
Run Code Online (Sandbox Code Playgroud)
我正在运行的Android 0.5.2工作室与摇篮1.11与插件0.9.0上的Mac OSX
我的项目结构如下;
MyProject/
src/
androidTest/
java/
com.myproject.app.test/
… (tests source code) …
main/
java/
com.myproject.app/
… (source code) …
res/
… (resources code) …
build.gradle
Run Code Online (Sandbox Code Playgroud)
我的build.gradle文件类似于以下内容:
…
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
versionCode 12
versionName "2.0"
minSdkVersion 9
targetSdkVersion 19
testPackageName "com.test.foo"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
}
…
Run Code Online (Sandbox Code Playgroud)
如果有人有任何建议,我会非常高兴在这里.
我正在寻找一种在 android 测试中模拟 api 响应的方法。
我已经读过机器人电可以用于此,但我真的很感激这方面的任何建议。
我正在使用Retrofit进行异步和同步api调用.
对于两者,我都定义了一个自定义错误处理程序来处理未经授 对于同步调用,我已经在接口方法上声明了自定义异常,我用try/catch包围了接口实现,它完美无缺.我可以捕获未经授权的例外情况.
我已尝试使用回调的异步调用,但它不起作用.而不是在try/catch中捕获Exception,我必须在回调的失败方法中处理它.
这是接口方法:
@GET("getGardenGnomes")
void getGardenGnomes(@Header("Authorisation") String authorisation, Callback<GardenGnomes> callback) throws UnauthorisedException;
Run Code Online (Sandbox Code Playgroud)
这是实施:
void onClick() {
try {
getGardenGnomes()
} catch (UnauthorisedException exception) {
// .... handle the exception ....
}
}
void getGardenGnomes() throws UnauthorisedException {
// .... get client etc etc ....
client.getGardenGnomes(authorisation, new Callback<GardenGnomes>() {
@Override
public void success(GardenGnomes gardenGnomes, Response response) {
// .... do something ....
}
@Override
public void failure(RetrofitError error) {
// .... handle error ....
}
}
);
}
Run Code Online (Sandbox Code Playgroud)
问题是: …