简体   繁体   中英

Run JVM unit test as an Android instrumented test

I added unit tests (that run on bare JVM) to a Kotlin library, and I'd like to also run the code in ART (Android Runtime) and Dalvik VM against the Android API, reusing the defined tests in the test sourceSet, and running them with tests in the androidTest sourceSet, on a real device or in an emulator.

Is this possible, and if so, how?

The reason why I want to do this is that I run some code on the main thread when on a real device, falling back to a custom thread if an error/exception is thrown because not running on a real device, but I also want to test the code when it doesn't fallback because it is running on a real device which has access to the main thread.

Yes, move the JVM tests from 'test' directory to androidTest target. It runs the JVM tests along with instrumentation tests.

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