Android - Is it possible to access instrumened test and unit test classes in androidTest and test folders programmatically?

时间:2019-04-08 13:35:09

标签: android kotlin

Is there a way to access the test classes in AndroidTest and test folders from my code? I can access tests placed in the same folder than my activity but not from these test folders.

Here is a picture to explain what I mean:

enter image description here

I am using Android Studio and Kotlin. Thanks in advance for any help

1 个答案:

答案 0 :(得分:0)

is there a way to access the test classes in androidTest and test folders from code?

If by "from code" you mean "from classes in the main/ source set", then no, that is not possible.

I want to do that to run test after an admin clicked a button.

Android tests (androidTest and test) are run by the Android SDK tools. Unit tests (test) are run on a development machine, not the device. Instrumented tests (androidTest) require special permissions to run and cannot be executed directly by an ordinary Android app.