重复条目:Android中的org / junit / ClassRule.class

时间:2017-01-04 06:31:48

标签: android junit android-espresso android-espresso-recorder

我想在Andorid中运行由espresso test编写的Record Espresso Test。测试以这种方式编写

测试

import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;

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

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.replaceText;
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.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import android.support.multidex.MultiDex;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class CarParki_SignIn_Test {

    @Rule
    public ActivityTestRule<CarParki_O> mActivityTestRule = new ActivityTestRule<>(CarParki_O.class);

    @Test
    public void carParki_SignIn_Test() {
        ViewInteraction appCompatButton = onView(
                allOf(withId(R.id.id_signIn), withText("SIGN IN"),
                        withParent(allOf(withId(R.id.buttonsLayout),
                                withParent(withId(R.id.content_login_or_signup)))),
                        isDisplayed()));
        appCompatButton.perform(click());

        ViewInteraction appCompatEditText = onView(
                allOf(withId(R.id.field_email),
                        withParent(withId(R.id.email_password_fields)),
                        isDisplayed()));
        appCompatEditText.perform(replaceText("awais@gmail.com"), closeSoftKeyboard());

        ViewInteraction appCompatEditText2 = onView(
                allOf(withId(R.id.field_password),
                        withParent(withId(R.id.email_password_fields)),
                        isDisplayed()));
        appCompatEditText2.perform(replaceText("444444"), closeSoftKeyboard());

        ViewInteraction appCompatButton2 = onView(
                allOf(withId(R.id.email_sign_in_button), withText("Sign In"),
                        withParent(withId(R.id.email_password_buttons)),
                        isDisplayed()));
        appCompatButton2.perform(click());

    }

}

在跑步时,它给出了;

  

错误:任务&#39;:app:transformClassesWithJarMergingForDebugAndroidTest&#39;执行失败。   com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:org / junit / ClassRule.class

我的gradle文件是;

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "com.example.fyp_awais.carparki_o"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations , '
    })
    androidTestCompile('com.android.support.test:testing-support-lib:0.1')
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.google.firebase:firebase-database:10.0.1'
    compile 'com.google.android.gms:play-services:10.0.1'
    testCompile 'junit:junit:4.12'
}



apply plugin: 'com.google.gms.google-services'

这里有什么不对吗?

1 个答案:

答案 0 :(得分:1)

当您添加com.android.support:multidex依赖项时,实际上添加了一些与其他依赖项冲突的依赖项。

我解决了它:

  1. 搜索课程,在你的情况下是&#34; RequestWeakReference.class&#34; (在AndroidStudio中只需按Windows上的Ctrl + N或Mac上的CMD-O)
  2. 查看哪个jar包含它 - Android Studio会在弹出窗口中编写它。
  3. 从所有版本中排除它,例如:

     android {
     configurations{
        all*.exclude module: 'servlet-api'
    }