简体   繁体   English

Android Studio Espresso空测试套件

[英]Android Studio Espresso Empty Test Suite

When I run my test method that uses Espresso, it prompts me to choose an emulator, and I pick my existing emulator with my application already started. 当我运行使用Espresso的测试方法时,它会提示我选择一个模拟器,然后在我的应用程序已启动的情况下选择现有的模拟器。 The emulator subsequently automatically reboots my application, and then displays that that the test suite is empty. 模拟器随后自动重新启动我的应用程序,然后显示测试套件为空。

错误

My espresso test case is located in the androidTest folder of the same module as the activity I'm trying to test. 我的espresso测试用例位于与我要测试的活动相同的模块的androidTest文件夹中。 I wrote a simple "isDisplayed()" type of a test and right clicked the method and clicked run. 我编写了一个简单的“ isDisplayed()”类型的测试,然后右键单击该方法并单击“运行”。 I've taken a look at the other questions on Stack Overflow and other resources, but I can't figure out what is causing this problem. 我看了关于Stack Overflow和其他资源的其他问题,但我不知道是什么导致了此问题。 The logcat displays nothing and when I tried putting Log.d("debug", "hello hello") in the test method (shown below), nothing shows up in the logcat, nor does anything display when I try putting a System.out.println("hello") in the test method. logcat不显示任何内容,当我尝试将Log.d(“ debug”,“ hello hello”)放入测试方法(如下所示)时,logcat中没有任何显示,而当我尝试将System.out放置时,也没有任何显示.println(“ hello”)在测试方法中。 It seems that although I run the method, none of my code is being run! 看来,尽管我运行了该方法,但是我的代码都没有被运行!

Below is some of my build.grade. 以下是我的一些build.grade。

apply plugin: 'com.android.application'

android {
   compileSdkVersion 17
   buildToolsVersion "21.1.2"
   defaultConfig {
       applicationId "x"
       minSdkVersion 17
       targetSdkVersion 17
       versionCode 1
       versionName "1.0"

       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
   }


    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'LICENSE.txt'
    }
}


configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:22.2.0'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile 'com.android.support.test:rules:0.3'
    androidTestCompile 'com.android.support.test:runner:0.3'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
}

Here is the test case that I'm trying to run. 这是我要运行的测试用例。

@RunWith(AndroidJUnit4.class)
public class EspressoTest1 extends ActivityInstrumentationTestCase2<P1>{


    private P1 mActivity;

    public EspressoTest1() {
        super(P1.class);
    }

    public void setUp() throws Exception {

        super.setUp();
        injectInstrumentation(InstrumentationRegistry.getInstrumentation());
        mActivity = getActivity();

    }

    public void Happy_test() {

        onView(withId(R.id.Btn)).check(matches(isDisplayed()));

    }
}

测试配置

And this is the test run configuration. 这是测试运行配置。

Your test is missing @Test annotation. 您的测试缺少@Test批注。 So as your setup method is missing @Before 因此,由于您的设置方法缺少@Before

Maybe this will help other people (like Igor Ganapolsky). 也许这会帮助其他人(例如Igor Ganapolsky)。

When you are using annotations from Espresso library you have to add testInstrumenatationRunner to your gradle file. 使用Espresso库中的注释时,必须将testInstrumenatationRunner添加到gradle文件中。 Missing this line occurs the same error message " Empty test suite " 缺少此行会出现相同的错误消息“ Empty test suite

defaultConfig {
    applicationId "com.test.app"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM