繁体   English   中英

Android Studio Espresso空测试套件

[英]Android Studio Espresso Empty Test Suite

当我运行使用Espresso的测试方法时,它会提示我选择一个模拟器,然后在我的应用程序已启动的情况下选择现有的模拟器。 模拟器随后自动重新启动我的应用程序,然后显示测试套件为空。

错误

我的espresso测试用例位于与我要测试的活动相同的模块的androidTest文件夹中。 我编写了一个简单的“ isDisplayed()”类型的测试,然后右键单击该方法并单击“运行”。 我看了关于Stack Overflow和其他资源的其他问题,但我不知道是什么导致了此问题。 logcat不显示任何内容,当我尝试将Log.d(“ debug”,“ hello hello”)放入测试方法(如下所示)时,logcat中没有任何显示,而当我尝试将System.out放置时,也没有任何显示.println(“ hello”)在测试方法中。 看来,尽管我运行了该方法,但是我的代码都没有被运行!

以下是我的一些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'
}

这是我要运行的测试用例。

@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()));

    }
}

测试配置

这是测试运行配置。

您的测试缺少@Test批注。 因此,由于您的设置方法缺少@Before

也许这会帮助其他人(例如Igor Ganapolsky)。

使用Espresso库中的注释时,必须将testInstrumenatationRunner添加到gradle文件中。 缺少此行会出现相同的错误消息“ 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