Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - Kotlin Tests Throwing - Class not found - Empty test suite

When trying to run espresso tests written in Kotlin on Android Studio (as far as 3.2 Canary 9), I'm getting the error: Process finished with exit code 1 Class not found: "com.myproject.directoryofwinning.VerifyAppIsAwesomeTest"Empty test suite.

Strangely, Java tests in the same project have no issues.

Have tried to reset the configurations and suggested by others, but this doesn't seem to make any difference.

like image 261
user1228891 Avatar asked Apr 04 '18 16:04

user1228891


4 Answers

In the end I found that it was down to "test" being added to the end of the classname. Either moving the word Test to the front of the classname, or omitting it all together resolves the issue.

like image 159
user1228891 Avatar answered Nov 20 '22 10:11

user1228891


In my case using Android Studio 3.1.1, my Run/Debug Configurations were incorrect, probably due to to an automatic conversion of the config when updating Android Studio. My instrumented test config ended up being placed under "Android JUnit" configs, instead of "Android Instrumented Tests". Creating a new instrumented tests config for my particular class worked.

Also, the default configs created when right-clicking on my module's "Run All Tests" option fail to find my instrumented tests and run properly, resulting in

0 test classes found in package '<default package>' 
Process finished with exit code 254 
Empty test suite.

as the default config created popped up under Android JUnit. However, right-clicking on my package containing my instrumented tests creates it in the right category. I can also manually edit it to 'All in Module' and still execute my kotlin tests properly.

As an aside, I've also had the IDE give me the following misleading output before:

$ adb shell am instrument -w -r   -e package com.base.package.kotlintests -e debug false com.base.package.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests
Tests ran to completion.
Empty test suite.

Why did it say there was an empty test suite why I clearly have tests? Looking at the logs or running the adb command on a terminal revealed that my code was throwing an exception in my @BeforeClass setup! So no tests were executed, and everything completed trivially.

like image 4
qix Avatar answered Nov 20 '22 10:11

qix


It took me a couple of tries to figure this out, but it ended up being due to missing the gradle changes needed to enable kotlin.

....
apply plugin: 'kotlin-android'
android {
    ....
}
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.21"
    ....
}
like image 4
mattfred Avatar answered Nov 20 '22 10:11

mattfred


Rebuild project, File > Invalidate Caches / Retart..., remove app\build folder, kill adb from processes, restart emulator.

like image 1
CoolMind Avatar answered Nov 20 '22 10:11

CoolMind