简体   繁体   English

将JVM单元测试作为Android的测试运行

[英]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. 我将单元测试(在裸机上运行)添加到Kotlin库,并且我还想针对Android API在ART(Android运行时)和Dalvik VM中运行代码,重用test sourceSet中定义的test ,以及使用androidTest sourceSet,真实设备或仿真器中的测试运行它们。

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. 是的,将JVM测试从“测试”目录移动到androidTest目标。 It runs the JVM tests along with instrumentation tests. 它运行JVM测试以及检测测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM