我第一次开始为Android应用程序编写测试用例,我进行了很多搜索,但找不到完整阶段的正确方法
就像我在“ androidTest”文件夹中测试Instrumentation测试用例一样
下面是LoginTestCases的代码
@Test
public void loginUserAccount() {
NetworkHelper.MOCK_URL =
String userName = "abacus@hotmail.com";
String password = "abacus#112";
boolean keepMeLoggedInChecked = false;
boolean touchIdEnabled = false;
boolean optIn = false;
mAuthenticationService.logIn(userName, password, keepMeLoggedInChecked, touchIdEnabled, optIn).done(new DoneCallback<LogInResponse>() {
@Override
public void onDone(final LogInResponse result) {
Assert.assertEquals(true,true);
}
}).fail(new FailCallback<Throwable>() {
@Override
public void onFail(Throwable result) {
Assert.assertEquals(true,false);
}
});
}
为了进行测试,我需要将 MOCK_URL值更改为“ /” ,以便实现MockWebServer并选择所需的响应,我使用了静态变量MOCK_URL,如下面的代码
public class NetworkHelper {
private final OkHttpClient mOkHttpClient;
public static HttpUrl MOCK_URL = null;
public NetworkHelper(OkHttpClient httpClient) {
mOkHttpClient = httpClient;
}
public Retrofit initialize(String baseUrl) {
if(MOCK_URL!=null) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(MOCK_URL)
.addConverterFactory(JacksonConverterFactory.create())
.client(mOkHttpClient)
.build();
return retrofit;
我知道,如果有人知道另一种方法,那么静态方法是不合适的,请给我解决方案。