Android Espresso:"未发现任何测试" ,"流程崩溃"

时间:2015-10-18 10:56:20

标签: android android-espresso

在使用Espresso测试我的Android应用时,我注意到运行配置了chaining state的AndroidTest没有找到测试,而运行All in Module成功。

我创建了以下可重现的案例:

  • 使用向导使用minSdk 8创建新的干净应用程序并清空活动
  • 使用espresso依赖项等配置gradle(见下文)
  • 使用选项All in Package创建AndroidTest Run Configuration,使用All in Module
  • 创建一个
  • 添加带测试的课程(见下文)
  • 使用All in Package运行:已通过测试
  • 使用All in Package运行:未找到任何测试

使用All in Module运行直到几天前一直运行良好。我记得的更改是将Android Studio升级到1.4并将All in Module升级到23.1.0,将Android Support Library升级到24.0.0。

顺便说一下。 Android Support Repositorygradlew connectedCheck现在也失败了。

有没有人有解决此问题的建议?

build.gradle for app:

gradlew createDebugAndroidTestCoverageReport

Test.java

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.xyz.apptest"
        minSdkVersion 8
        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'
        }
        debug {
            testCoverageEnabled true
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.0'

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1') {
        // Necessary if your app targets Marshmallow (since Espresso
        // hasn't moved to Marshmallow yet)
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
        // Necessary if your app targets Marshmallow (since Espresso
        // hasn't moved to Marshmallow yet)
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude module: 'recyclerview-v7'
    }
    androidTestCompile('com.android.support.test.espresso:espresso-idling-resource:2.2.1') {
        // Necessary if your app targets Marshmallow (since Espresso
        // hasn't moved to Marshmallow yet)
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestCompile('com.android.support.test:runner:0.4.1') {
        // Necessary if your app targets Marshmallow (since the test runner
        // hasn't moved to Marshmallow yet)
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestCompile('com.android.support.test:rules:0.4.1') {
        // Necessary if your app targets Marshmallow (since the test runner
        // hasn't moved to Marshmallow yet)
        exclude group: 'com.android.support', module: 'support-annotations'

    }
}

在运行窗口中跟踪:

@RunWith(AndroidJUnit4.class)
public class Test1 {

    @Rule
    public ActivityTestRule<MainActivity> activityTestRule =
            new ActivityTestRule<>(MainActivity.class, true, false);

    @Before
    public void setUp() {
        activityTestRule.launchActivity(new Intent());
    }

    @After
    public void cleanUp() {
    }

    @Test
    public void test() {
    }
}

logcat:未发现易受影响的差异。

1 个答案:

答案 0 :(得分:1)

从基于API 10的模拟器切换到API 17解决了这个问题。

尽管API 10在上周运行良好,但它已变得无法预测。有时它会运行,但大多数情况下都没有。删除单个测试方法可能会使其工作,将其放回可能会使其保持工作(或不工作)。试图第五次运行测试可能会再次运行...

更新2016-03-16 : 增加API 10仿真器的资源使得测试再次可用于API 10 ......

相关问题