简体   繁体   中英

Android Studio 1.3.2 + Espresso - No Test were found

I notified that my UI tests stopped working:

Each time when I trying to run test on the device i got the following message:

No tests were found

And the additional console output saying:

Running tests
Test running startedTest running failed: Instrumentation run failed due to 'java.lang.IllegalAccessError'
Empty test suite.

And when i tried to run test on emulator i got the following message:

Test running started
java.lang.IncompatibleClassChangeError: 
view.activity.SignUpActivity
SignUpActivityTest.<init>(SignUpActivityTest.java:25)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:54)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:228)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1853)

Finish

Here is the example of test class:

import android.app.Activity;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.ActivityInstrumentationTestCase2;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import xxxx.view.activity.SignUpActivity;

@RunWith(AndroidJUnit4.class)
public class SignUpActivityTest extends ActivityInstrumentationTestCase2<SignUpActivity> {

    private Activity mActivity;

    public SignUpActivityTest() {
        super(SignUpActivity.class);
    }

    @Before
    public void setUp() throws Exception {
        super.setUp();
        injectInstrumentation(InstrumentationRegistry.getInstrumentation());
        mActivity = getActivity();
    }

    // Insert scenario methods here
    @Test
    public void processTest() throws InterruptedException {
        TestHelper th = new TestHelper();
        th.insertTextIntoInput(R.id.input_sign_in_username, "test");

    }

}

And build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "cz.xxx.xxx"
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        // Enabling multidex support.
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}


repositories {
    jcenter()
    mavenCentral()
    maven { url "https://repo.commonsware.com.s3.amazonaws.com" }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    maven { url "https://jitpack.io" }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.google.android.gms:play-services:7.8.0'
    compile 'com.mcxiaoke.volley:library:1.0.18'
    compile 'com.orhanobut:logger:1.11'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.android.support:design:23.0.0'
    // UI TESTING DEPENDENCIES
    androidTestCompile 'com.android.support:support-annotations:23.0.0'
    androidTestCompile 'com.android.support.test:runner:0.3'
    androidTestCompile 'com.android.support.test:rules:0.3'
    //androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2'
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
    // ORM DATABASE DEPENDENCIES
    compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
    // STETHO CORE
    compile 'com.facebook.stetho:stetho:1.1.1'
    compile 'com.facebook.stetho:stetho-urlconnection:1.1.1'
    compile 'com.facebook.stetho:stetho-okhttp:1.1.1'
    // GOOGLE ANALYTICS
    compile 'com.google.android.gms:play-services-analytics:7.8.0'
    // JODA TIME FOR ANDROID
    compile 'net.danlew:android.joda:2.8.2'
    // SECURE SHARED PREFERENCES
    compile 'com.scottyab:secure-preferences-lib:0.1.3'
    // MATERIAL DIALOG
    compile 'com.avast:android-styled-dialogs:2.2.0'
    // SQL CIPHER
    compile 'com.commonsware.cwac:sqlcipher-for-android:3.3.1'
    // HTML PARSER
    compile 'org.jsoup:jsoup:1.8.3'
    // MULTIDEX SUPPORT
    compile 'com.android.support:multidex:1.0.0'
}

I tried almost everything to solve it but without the luck. Maybe some give me a right answer.

Many thanks for any advice.

Edit I tried to display Run/Debug Configuration and in the "Specific instrumentation runner" input was nothing.

So i inserted following (See. image below) but part of the String AndroidJUnitRunner is colored red.

在此输入图像描述

test name should start with

test

Try to rename your test to the following and re-run

testprocessTest()

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