【问题标题】:Android Studio Espresso Empty Test SuiteAndroid Studio Espresso 空测试套件
【发布时间】:2015-06-29 18:34:01
【问题描述】:

当我运行使用 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()));

    }
}

这是测试运行配置。

【问题讨论】:

    标签: android unit-testing android-studio android-espresso


    【解决方案1】:

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

    【讨论】:

    • 谢谢,在从 JUnit 导入 @Test@Before 然后清理和重建项目后,这样做了。
    • 这根本没有解决我的问题。其实我已经有了@Test@Before
    • @IgorGanapolsky Empty Test Suite 实际上可以是任何类型的问题 - 从 gradle 任务失败到配置错误的 @before 方法。在这种情况下,问题是什么很明显。你的情况可能完全不同。
    • 尝试在Edit Configuration stackoverflow.com/a/53715513/967131 中手动创建新的Android Instrumented Tests 配置
    【解决方案2】:

    也许这会帮助其他人(例如 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"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多