【问题标题】:android espresso testing : empty test suite. no tests were foundandroid espresso 测试:空的测试套件。没有找到测试
【发布时间】:2015-02-12 17:38:15
【问题描述】:

我在 windows 上运行 intelliJ idea 14.0.2 android 开发环境,并尝试使用 espresso UI 测试框架来测试我的应用程序。但是,当我按下运行进行 androidTest 配置时,我遇到以下情况:

Testing started at 12:09 PM ...
Waiting for device.
Target device: lge-nexus_5-05b1bd8af0ddba12
Uploading file
local path: C:\Users\AsiAnSeNsAtIoN\Documents\note\ECSE428\AssB_2\build\classes\main\AssB_2.apk
remote path: /data/local/tmp/com.cyc115.VectorCalculator
Installing com.cyc115.VectorCalculator
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.cyc115.VectorCalculator"
pkg: /data/local/tmp/com.cyc115.VectorCalculator
Success

Running tests
Test running startedFinish
Empty test suite.

这是截图:

我的测试类如下所示:

package com.cyc115.VectorCalculator.test;

import android.support.test.espresso.assertion.ViewAssertions;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
import com.cyc115.VectorCalculator.MyActivity;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

@LargeTest
public class MyActivityTest extends ActivityInstrumentationTestCase2<MyActivity> {

    public MyActivityTest(){
        super (MyActivity.class);
    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        getActivity();
        fail();
    }
    @SmallTest
    public void testListGoesOverTheFold() {
        onView(withText("Hello world")).check(ViewAssertions.matches(isDisplayed()));
    }
}

这是我的项目结构以防万一:

我的测试配置:

还有我的 androidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.cyc115.VectorCalculator"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="21"/>

    <instrumentation
    android:name="android.support.test.runner.AndroidJUnitRunner"
    android:targetPackage="com.cyc115.VectorCalculator"
    />

    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <activity android:name="com.cyc115.VectorCalculator.MyActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

【问题讨论】:

    标签: android intellij-idea gradle android-espresso ui-testing


    【解决方案1】:

    我找到了一种解决方法:使用基于社区版 intelliji idea 的 android-studio,而不是高级版 intelliji idea。创建一个新项目并从那里设置 espresso。更多细节参考sample project中的gradle文件:

    希望对你有帮助。

    http://developer.android.com/sdk/index.html

    【讨论】:

    【解决方案2】:

    在方法之前使用注解@Test,您已经在其中编写了所有 ESPRESSO UI 测试。这可能有效。

    【讨论】:

      猜你喜欢
      • 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
      相关资源
      最近更新 更多