gpt4 book ai didi

android - Espresso 测试不更新

转载 作者:行者123 更新时间:2023-12-03 04:48:50 27 4
gpt4 key购买 nike

我对 espresso 有问题。

该测试工作正常,但是每当我更改测试中的某些内容并运行它们时:测试不会更新

基本上运行测试的“旧”版本。
为了强制测试更新,我使用了Gradle任务: uninstallAll

这是我的配置:

  • 测试
    package com.shockn745.moovin5.main;

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

    import com.shockn745.moovin5.R;

    import org.junit.Before;
    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.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 org.hamcrest.core.AllOf.allOf;

    /**
    * UI Test for the Main Screen
    */
    @RunWith(AndroidJUnit4.class)
    @LargeTest
    public class MainScreenTest {

    private final static String WRONG_DURATION = "asdssssssssf";
    private final static String RIGHT_DURATION = "40";

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

    @Before
    public void initTest() {
    // Do nothing for now
    }

    @Test
    public void enterDuration_success() {
    // Type text and then press the button.
    onView(withId(R.id.main_edit_text))
    .perform(typeText(RIGHT_DURATION), closeSoftKeyboard());
    onView(withId(R.id.main_button)).perform(click());

    // Check that Motivation Activity is displayed
    onView(withId(R.id.motivation_toolbar)).check(matches(isDisplayed()));
    }

    @Test
    public void enterDuration_parse_error() {
    // Type text and then press the button.
    onView(withId(R.id.main_edit_text))
    .perform(typeText(WRONG_DURATION), closeSoftKeyboard());
    onView(withId(R.id.main_button)).perform(click());

    // Check that the text was changed.
    onView(allOf(
    withId(android.support.design.R.id.snackbar_text),
    withText(R.string.main_error_snackbar)
    )).check(matches(isDisplayed()));
    }

    @Test
    public void enterDuration_empty_error() {
    // Press the button. with no text
    onView(withId(R.id.main_button)).perform(click());

    // Check that the text was changed.
    onView(allOf(
    withId(android.support.design.R.id.snackbar_text),
    withText(R.string.main_error_snackbar)
    )).check(matches(isDisplayed()));
    }
    }
  • Gradle
    apply plugin: 'com.android.application'

    android {
    compileSdkVersion 'Google Inc.:Google APIs:23'
    buildToolsVersion "23.0.2"

    defaultConfig {
    applicationId "com.shockn745.moovin5"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'

    }
    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    }
    }

    /*
    Resolves dependency versions across test and production APKs, specifically, transitive
    dependencies. This is required since Espresso internally has a dependency on support-annotations.
    */
    configurations.all {
    resolutionStrategy {
    force 'com.android.support:support-annotations:23.0.1'
    }
    }

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    // Android libraries
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'

    // Google libraries
    compile 'com.google.guava:guava:19.0'

    // Network operations
    compile 'com.mcxiaoke.volley:library:1.0.19'

    // Unit testing
    testCompile 'junit:junit:4.12'
    testCompile "org.mockito:mockito-core:1.9.5"
    testCompile "org.hamcrest:hamcrest-all:1.3"

    // UI testing
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile "com.android.support.test:runner:0.4.1"
    androidTestCompile "com.android.support.test:rules:0.4.1"

    // External libraries
    compile 'com.jakewharton:butterknife:7.0.1'
    }
  • 运行配置

  • Run config

    有任何想法吗 ?

    非常感谢,如果您能找到一个解决方案:)

    最佳答案

    请转到Edit Configurations-> Main Screen Test-> Miscellaneous->并禁用Skip installation if apk has not changed

    关于android - Espresso 测试不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34906069/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com