简体   繁体   中英

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.

I created the following reproducible case:

  • Use wizard to create new clean application with minSdk 8 and empty Activity
  • Configure gradle with espresso dependencies etc. (see below)
  • Create AndroidTest Run Configuration with option All in Module and one with All in Package
  • Add class with tests (see below)
  • Run with All in Package : Test passed
  • Run with All in Module : No tests were found

Running with All in Module worked fine until a few days ago. 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.

Btw. also gradlew connectedCheck and gradlew createDebugAndroidTestCoverageReport fail now.

Does anyone have suggestions to solve this issue?

build.gradle for app:

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

@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.

Switching from emulator based on API 10 to API 17 fixed the issue.

Although API 10 was running fine until last week, it has become unpredictable. 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM