Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a JUnit Test in android studio?

i think tests in the instruementTest should relevant to android, so need i add an addtional source folder such as src/test/java? it looking that the testfile in src/test/java didn't compiled.

how can i run a junit test independently?

how can i run the junit test only in a command line, no the instrumentTest about android?

enter image description here

enter image description here

or put and junit test in the instruementTest folder and call

     ./gradlew connectedInstrumentTest

but,the unit test won't run at all.

like image 954
log1000 Avatar asked Jun 21 '13 06:06

log1000


People also ask

Can I use JUnit 5 in Android?

There is experimental support for Android instrumentation tests, which requires some additional configuration & dependencies. Furthermore, because JUnit 5 is built on Java 8 from the ground up, its instrumentation tests will only run on devices running Android 8.0 (API 26) or newer.

How do you run a unit test?

To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).


1 Answers

I think this is not possible if you only have the Android plugin in your build.gradle. The only testing that is supported in the Android plugin is in the InstrumentTest folder. The normal test folder is only used by other plugins.

Next to that there is probably support needed in Android Studio itself. But not sure about that.

like image 177
Peter Fortuin Avatar answered Sep 29 '22 16:09

Peter Fortuin