我希望在Andorid中运行Record Espresso Test
编写的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());
}
}
跑步时,它会屈服;
错误:任务":app:transformClassesWithJarMergingForDebugAndroidTest"的执行失败。com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:org/junit/ClassRule.class
我的渐变文件是;
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'
这里有错吗?
当您添加com.android.support:multex依赖项时,您实际上添加了一些与其他依赖项冲突的依赖项。
我通过以下方式解决了问题:
- 搜索类,如果是"RequestWeakReference.class"(在AndroidStudio中,只需在Windows上按Ctrl+N或在Mac上按CMD-O)
- 看看哪个罐子包含它-安卓工作室会在弹出窗口中写入它
-
将其从所有构建中排除,例如:
android { configurations{ all*.exclude module: 'servlet-api' }