WireMock和Android,浓缩咖啡仪器化单元测试==>;由于';java.lang.NoClassDefFoundError';

WireMock和Android,浓缩咖啡仪器化单元测试==>;由于';java.lang.NoClassDefFoundError';,android,android-espresso,wiremock,Android,Android Espresso,Wiremock,Android Studio 2.3.1,Java 8 在“androidTest”文件夹中,我写下了我的安卓系统和浓缩咖啡单元测试。而且工作很好。 此处代码: package com.myproject.fragment; import android.content.Context; import android.content.Intent; import android.support.test.InstrumentationRegistry; import android.s

Android Studio 2.3.1,Java 8

在“androidTest”文件夹中,我写下了我的安卓系统和浓缩咖啡单元测试。而且工作很好。 此处代码:

    package com.myproject.fragment;

import android.content.Context;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.myproject.R;
import com.myproject.activity.MainActivity;

import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.myproject.CustomMatchers.withListSize;
import static org.hamcrest.Matchers.anything;
import static org.hamcrest.Matchers.containsString;

@RunWith(AndroidJUnit4.class)
public class MyInstrumentedClassTest {
    private Context context;
    private static final String EXIST_SURNAME = "TestSurName";

    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, true, false);

    @Before
    public void init() {
        context = InstrumentationRegistry.getTargetContext();
        Intent intent = new Intent();
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        mActivityRule.launchActivity(intent);
        onView(withId(R.id.peopleTextView)).perform(click());
    }

    @Test
    public void searchBySurname() {
        onView(withId(R.id.searchView)).perform(click());
        onView(withId(android.support.design.R.id.search_src_text))
                .perform(typeText(EXIST_SURNAME))
                .perform(closeSoftKeyboard());
        onView(withId(R.id.containerNotEmptyListView)).check(matches(withListSize(1)));
        onData(anything()).atPosition(0).onChildView(withText(containsString(EXIST_SURNAME)))
                .check(matches(isDisplayed()));
    }
}
当我运行插入指令的意式浓缩咖啡单元测试“searchBySurname”时,它运行良好。好的

现在我想使用WireMock为http请求/响应创建单元测试。 所以我添加了新的依赖项。 这是我的新版本。gradle:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
       multiDexEnabled = true
    }
    testBuildType "my_build_type"
}

dependencies {
    testCompile 'junit:junit:4.12'
    testCompile 'org.powermock:powermock-api-mockito:1.6.6'
    testCompile 'org.powermock:powermock-module-junit4:1.6.6'
    testCompile "org.mockito:mockito-core:1.10.19"

   androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
}
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
       multiDexEnabled = true
    }
    testBuildType "my_build_type"
}

dependencies {
    testCompile 'junit:junit:4.12'
    testCompile 'org.powermock:powermock-api-mockito:1.6.6'
    testCompile 'org.powermock:powermock-module-junit4:1.6.6'
    testCompile "org.mockito:mockito-core:1.10.19"

    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

    //WireMock
    androidTestCompile("com.github.tomakehurst:wiremock:2.6.0") {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
        exclude group: 'org.ow2.asm', module: 'asm'
        exclude group: 'org.json', module: 'json'
    }
    androidTestCompile('com.squareup.okhttp3:mockwebserver:3.5.0') {
        exclude module: 'okhttp'
    }
}
但现在,当我运行插入指令的浓缩咖啡单元测试“searchBySurname”时,我得到了一个错误:

Testing started at 17:20 ...

05/15 17:20:26: Launching searchOneContactBy...() (1)
$ adb push D:\dev\myproject\app\build\outputs\apk\app-my_build_type.apk /data/local/tmp/com.myproject
$ adb shell pm install -r "/data/local/tmp/com.myproject"
    pkg: /data/local/tmp/com.myproject
Success


$ adb push D:\dev\myproject\app\build\outputs\apk\app-my_build_type-androidTest.apk /data/local/tmp/com.myproject.test
$ adb shell pm install -r "/data/local/tmp/com.myproject.test"
    pkg: /data/local/tmp/com.myproject.test
Success


Running tests

$ adb shell am instrument -w -r   -e debug false -e class com.myprojectd.fragment.MyInstrumentedClassTest#searchOneContactBySurname com.myproject.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests
Test running failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'
Empty test suite.