简体   繁体   中英

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.

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.

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.

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"
    ....
}

重建项目,文件>无效缓存/重新启动...,删除app \\ build文件夹,从进程中删除adb ,重新启动模拟器。

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