Cannot run unit tests in Android Studio

I try to run my unit tests again for two days, every time 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 when trying to run both a test class and just methods. I tried to clear all test configurations and rebuild the project. In addition, I was able to find other people having the same problem , so the proposed solutions did not help fix my problem.

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 tests:

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

Thanks!

Update

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

Therefore, changing the links to:

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

To:

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

However, I cannot create new tests or even rename my test methods. For example, if I renamed from:

 @Test public void testVideoListToTimedClips() throws Exception { 

in

 @Test public void testVideoListToTimedClips2() throws Exception { 

I get an error message:

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

Update 2

Trying to find out, it looks like Android Studio keeps a link to the old version of the tests.

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

 @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 starts the old method:

enter image description here

+4
source share
5 answers

Are you using Android Studio 2.3.0-beta1? If so, there is a bug due to which your unit tests are not created when you try to run them.

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

This issue should be fixed in the next version of the canary / beta version of Android Studio.

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

+7
source

I ran into a similar type of problem.

I built using the following command:

 gradle clean build -x test 

This skips the test cases.

try instead: gradle clean build

Clean up the project in the IDE. This will download the last class file and update its links.

+1
source

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

 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
0
source

I was able to fix the problem by changing the links in the manifest file:

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

To:

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

In addition, after each change in the tests, I need to do my project manually.

0
source

I had a similar problem. You need to check if there is a problem in Android code or studio. try running unit test using command line / terminal

 ./gradlew testDevelopDebugUnitTest 

DevelopDebug is a flavor that I have in my code, so it may be different from yours. If this command succeeds, the problem occurs in android studio.

As soon as I run this command manually, then the problem is fixed (I'm not sure about this reason). I hope you guys help. thank you

0
source

Source: https://habr.com/ru/post/1262186/


All Articles