7

I'm trying to make my unit tests work again for two days now, every time that I try to run them I get this error:

Process finished with exit code 1
Class not found: "XXXXX.XXXXX.XXXXX.XXX"Empty test suite.

This happens trying to run both the test class, or just the methods. I've tried to clean all the test configurations and rebuild the project. Furthermore, I was able to find other people having the same problem, therefore, the proposed solutions were not effective to fix my issue.

This is my gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.1'

    defaultConfig {
        applicationId "XXXXXXXXXX"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0.0"
        multiDexEnabled true
    }
    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    dataBinding {
        enabled = true
    }
}

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        // The Fabric Gradle plugin uses an open ended version to react
        // quickly to Android tooling updates
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'me.tatarka:gradle-retrolambda:3.4.0'
    }
}

apply plugin: 'io.fabric'
apply plugin: 'me.tatarka.retrolambda'

ext {
    supportLibVersion = '25.1.0'  // variable that can be referenced to keep support libs consistent
    jomlVersion = '1.8.4'
}

repositories {
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile "com.android.support:appcompat-v7:${supportLibVersion}"
    compile "com.android.support:design:${supportLibVersion}"
    compile "com.android.support:recyclerview-v7:${supportLibVersion}"
    compile "com.android.support:cardview-v7:${supportLibVersion}"
    compile "com.android.support:support-v4:${supportLibVersion}"
    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar')
    {
        transitive = true;
    }
    compile project(':circular-slider')
    compile project(':gpuimage-plus')
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'net.protyposis.android.mediaplayer:mediaplayer:4.2.2-rc1'
    compile 'net.protyposis.android.mediaplayer:mediaplayer-dash:4.2.2-rc1'
    compile 'com.google.code.gson:gson:2.7'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.writingminds:FFmpegAndroid:0.3.2'
    compile 'com.makeramen:roundedimageview:2.3.0'
    compile 'io.reactivex:rxjava:1.2.4'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'com.minimize.android:rxrecycler-adapter:1.2.2'
    compile "org.joml:joml:${jomlVersion}"
    provided 'org.glassfish:javax.annotation:10.0-b28'
    compile 'org.jetbrains:annotations-java5:15.0'
    compile 'com.annimon:stream:1.1.3'
    testCompile 'org.mockito:mockito-core:1.10.19'
    testCompile 'org.powermock:powermock-api-mockito:1.6.5'
    testCompile 'org.powermock:powermock-module-junit4-rule-agent:1.6.5'
    testCompile 'org.powermock:powermock-module-junit4-rule:1.6.5'
    testCompile 'org.powermock:powermock-module-junit5:1.6.5'
    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
    compile 'com.android.support:multidex:1.0.1'
}

And the beginning of the class with the tests:

@PrepareForTest({XXXXXX.class, XXXXXX.class, XXXXXX.class, XXXXXX.class})
@RunWith(PowerMockRunner.class)
public class VideoPlayerModelUnitTest {

Thanks!

Update

I was able to fix partially the problem by changing the references in my AndroidMaifest file.

Therefore, changing the references from:

<activity android:name="com.myapp.MusicSelector.MusicSelectorActivity"/>

To:

<activity android:name=".MusicSelector.MusicSelectorActivity"/>

However, I can't create new tests or even rename my tests methods. For example, if I rename from:

@Test
public void testVideoListToTimedClips() throws Exception {

to:

@Test
public void testVideoListToTimedClips2() throws Exception {

I get the error:

java.lang.Exception: No tests found matching Method testVideoListToTimedClips2(io.collect.collect.functional.VideoPlayerModelIntegrationTest) from org.junit.internal.requests.ClassRequest@15eb5ee5

Update 2

Trying things out, seems like Android Studio is keeping the reference to the an old version of the tests.

I changed the name of the test method from testVideoListToTimedClips to testVideoListToTimedClips2 resulting in a test class like that:

@PrepareForTest({VideoPlayerModel.class, MediaPlayer.class, Common.class})
@RunWith(PowerMockRunner.class)
public class testVideoPlayerModelIntegration {
    @Test
    public void testVideoListToTimedClips2() throws Exception {

And when I run the test class, Android Studio runs the old method:

enter image description here

Community
  • 1
  • 1
Mateus Zitelli
  • 1,222
  • 1
  • 13
  • 23

6 Answers6

8

Are you using Android Studio 2.3.0-beta1? If so, there's a bug that causes your unit tests to not get built when you try to run them.

You can work around the issue by first running Make project and then Run each time you want to run the unit tests.

This issue is supposed to be fixed in the next canary/beta version of Android studio.

Source: https://code.google.com/p/android/issues/detail?id=230688

starkej2
  • 11,391
  • 6
  • 35
  • 41
  • 1
    Yes, that was exactly my case. I've found the solution after some struggle, however, I'll mark your answer as correct because of the valuable information. Thanks anyway! – Mateus Zitelli Jan 04 '17 at 22:14
  • What was the solution you found? Might help me :P – starkej2 Jan 04 '17 at 23:35
  • 1
    I've create Run/Debug configuration with the required tasks added manually to the Gradle-aware make. – Mateus Zitelli Jan 05 '17 at 11:35
  • Thank you, make project was the last piece of the puzzle for me. Should also mention that my MultiDexTestRunner class was not public, and that caused me some issues after I'd sorted this out. So make your test runner public too – Saik Caskey Aug 02 '17 at 11:30
2

I was facing similar type of issue.

I was building using following command :

gradle clean build -x test

This skips the test cases.

instead try : gradle clean build

Clean your project in IDE. This will load latest class file and refresh its references.

Siddharth Kumar
  • 86
  • 2
  • 13
  • Thanks for the suggestion, however, I've tried to clean the project through Android Studio, without success in solving the problem. – Mateus Zitelli Jan 02 '17 at 17:52
1

I had similar issue. You need to check whether the issue is in the code or android studio. try run unit test using command prompt / terminal

./gradlew testDevelopDebugUnitTest

DevelopDebug is flavour that I have in the code so it might be different with yours. If that command is executed successfully then the issue is in android studio.

Once I run this command manually then the issue fix itself ( I'm not sure the reason though ). Hopefully can help you guys. Thank you

surga
  • 1,436
  • 21
  • 25
0

I was able to fix the problem by changing the references in the Manifest file from:

<activity android:name="com.myapp.MusicSelector.MusicSelectorActivity"/>

To:

<activity android:name=".MusicSelector.MusicSelectorActivity"/>

Also, after every change on the tests I need to make my project manually.

Mateus Zitelli
  • 1,222
  • 1
  • 13
  • 23
-1

At some point you should declare your test runner in the module gradle config. For example inside defaultConfig:

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
donfuxx
  • 11,277
  • 6
  • 44
  • 76
-1

Right click on the class which you want to test and click run.

Sriraksha
  • 459
  • 1
  • 8
  • 15