1

我正在使用 robolectric 单元测试。当我尝试将异步任务与 Web 服务调用一起使用时,我遇到了以下问题。

我的 build.gradle 配置

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
testOptions {
unitTests.all {
// configure the set of classes for JUnit tests
include '/*Test.class'
//exclude '/espresso/*/.class'

        // configure max heap size of the test JVM
        maxHeapSize = "2048m"
        systemProperty 'robolectric.dependency.repo.url', 'https://local-mirror/repo'
        systemProperty 'robolectric.dependency.repo.id', 'local'
    }

}
productFlavors {
    // Define separate dev and prod product flavors.
    dev {
        // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
        // to pre-dex each module and produce an APK that can be tested on
        // Android Lollipop without time consuming dex merging processes.
        minSdkVersion 21
    }
    prod {
        // The actual minSdkVersion for the application.
        minSdkVersion 18
    }
}
defaultConfig {
    applicationId "mypackage name"
    targetSdkVersion 23
    versionCode 8
    versionName "1.6.0"
    multiDexEnabled true
}
dependencies{
testCompile ('junit:junit:4.12')
testCompile 'org.hamcrest:hamcrest-core:1.1'
testCompile 'org.hamcrest:hamcrest-library:1.1'
testCompile 'org.hamcrest:hamcrest-integration:1.1'
testCompile "org.robolectric:robolectric:3.0"
testCompile "org.robolectric:shadows-multidex:3.0"

}

这是我的 LoginActivityTest

@Test
public void loginSucess(){
LoginActivity loginActivity = Robolectric.setupActivity(LoginActivity.class);
emailView.setText("testpay4@gmail.com");
passwordView.setText("123456");
assertNotNull("email view is null",emailView);
assertNotNull("password view is null",passwordView);
assertNotNull("login buton is null",btnLogin);
assertEquals("login sucess",Constants.testSucess,loginActivity.attemptLoginWithTest(emailView.getText().toString(),passwordView.getText().toString()));
btnLogin.performClick();
ShadowApplication application = shadowOf(RuntimeEnvironment.application);
assertThat("Next activity has started", application.getNextStartedActivity(), is(notNullValue()));

}

当我运行登录活动时,我遇到了这个问题**

“ java.lang.NoClassDefFoundError: javax/net/ssl/DistinguishedNameParser”**

4

0 回答 0