简体   繁体   English

Android Espresso:“没有找到测试”,“进程崩溃”

[英]Android Espresso: “No test were found” , “Process crashed”

When testing my Android app with Espresso, I noticed that running an AndroidTest configured with All in Module finds no tests, while running All in Package succeeds. 在使用Espresso测试我的Android应用程序时,我注意到运行配置了All in Module的AndroidTest找不到测试,而运行All in Package成功。

I created the following reproducible case: 我创建了以下可重现的案例:

  • Use wizard to create new clean application with minSdk 8 and empty Activity 使用向导使用minSdk 8创建新的干净应用程序并清空活动
  • Configure gradle with espresso dependencies etc. (see below) 使用espresso依赖项等配置gradle(见下文)
  • Create AndroidTest Run Configuration with option All in Module and one with All in Package 使用All in Module选项创建AndroidTest Run Configuration ,使用All in Package创建一个
  • Add class with tests (see below) 添加带测试的类(见下文)
  • Run with All in Package : Test passed 使用All in Package运行:测试通过
  • Run with All in Module : No tests were found All in Module使用All in Module运行:未找到任何测试

Running with All in Module worked fine until a few days ago. 使用All in Module运行直到几天前一直运行良好。 The changes I recall having made are upgrading Android Studio to 1.4 and upgrading Android Support Library to 23.1.0 and Android Support Repository to 24.0.0. 我记得有所做的更改正在升级的Android工作室1.4和升级Android Support Library到23.1.0和Android Support Repository到24.0.0。

Btw. 顺便说一句。 also gradlew connectedCheck and gradlew createDebugAndroidTestCoverageReport fail now. 还有gradlew connectedCheckgradlew createDebugAndroidTestCoverageReport现在失败了。

Does anyone have suggestions to solve this issue? 有没有人有解决这个问题的建议?

build.gradle for app: app.build.gradle:

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'

    }
}

Test.java Test.java

@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() {
    }
}

Trace in Run window: 在运行窗口中跟踪:

Testing started at 12:14 ...
Waiting for device.
Target device: 3_2_API_10 [emulator-5554]
Uploading file
    local path: C:\Users\xyz\Documents\Development\AndroidStudio\AppTest\app\build\outputs\apk\app-debug.apk
    remote path: /data/local/tmp/com.example.xyz.apptest
No apk changes detected.
Skipping file upload, force stopping package instead.
DEVICE SHELL COMMAND: am force-stop com.example.xyz.apptest
Uploading file
    local path: C:\Users\xyz\Documents\Development\AndroidStudio\AppTest\app\build\outputs\apk\app-debug-androidTest-unaligned.apk
    remote path: /data/local/tmp/com.example.xyz.apptest.test
No apk changes detected.
Skipping file upload, force stopping package instead.
DEVICE SHELL COMMAND: am force-stop com.example.xyz.apptest.test
Running tests
Test running startedTest running failed: Instrumentation run failed due to 'Process crashed.'
Empty test suite.

logcat: No susceptible differences found. logcat:没有发现易感差异。

Switching from emulator based on API 10 to API 17 fixed the issue. 从基于API 10的仿真器切换到API 17解决了该问题。

Although API 10 was running fine until last week, it has become unpredictable. 尽管API 10在上周运行良好,但它已变得无法预测。 Sometimes it runs, mostly it doesn't. 有时它会运行,但大多数情况下都没有。 Removing a single test method might make it work, and placing it back might keep it working (or not). 删除单个测试方法可能会使其工作,将其放回可能会使其保持工作(或不工作)。 Trying to run the test for the fifth time might make it work again... 试图第五次运行测试可能会再次运行...

UPDATE 2016-03-16 : Increasing the resources for the API 10 emulator made the test available for API 10 again... 更新2016-03-16 :增加API 10仿真器的资源使测试再次可用于API 10 ...

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

相关问题 Android Studio 1.3.2 + Espresso - 未找到测试 - Android Studio 1.3.2 + Espresso - No Test were found android espresso测试:空测试套件。 没有发现任何测试 - android espresso testing : empty test suite. no tests were found Android Espresso UI测试-测试运行失败:由于“进程崩溃”,仪表运行失败。 - Android Espresso UI test -— Test running failed: Instrumentation run failed due to 'Process crashed.' 在“由于程序崩溃”导致仪器运行失败后,如何恢复Android Espresso测试? - How to resume Android Espresso test after 'Instrumentation run failed due to 'Process crashed.''? 运行意式浓缩咖啡测试时,测试仪器过程崩溃 - Test instrumentation process crashed while running espresso tests AndroidX Espresso 测试:未找到测试且测试套件为空 - AndroidX Espresso Test: No tests were found and Empty test suite Android Espresso Test在多进程应用程序中 - Android Espresso Test in multi-process app 测试无法完成。 原因:“由于运行失败,仪器运行失败。 使用义式浓缩咖啡时 - Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Process crashed. when using Espresso Android Espresso测试:未找到类:…空测试套件 - Android Espresso test: Class not found: …Empty test suite 未找到浓缩咖啡测试 class - Espresso test class not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM