Running simple JUnit tests on Android Studio (IntelliJ) when using a Gradle-based configuration
android, android-studio, gradle, intellij-idea, junit
Solution
As of Android Studio 1.1, the answer is now simple: http://tools.android.com/tech-docs/unit-testing-support
Problem
I am using `Android Studio/IntelliJ` to build on an existing `Android` project and would like to add some simple `JUnit` unit tests. What is the right folder to add such tests on? The android `Gradle` plug-in defines a directory structure with `src/main/java` for the main source code and `src/instrumentTest/java` for `Android` tests. Trying to add my JUnit tests in instrumentTest didn't work for me. I can run it as an `Android` test (that's what that directory seems for) but that's not what I'm looking for - I just want to run a simple `JUnit` test. I tried creating a JUnit run configuration for this Class but that also didn't work - I'm supposing because I'm using a directory that is flagged as `Android` Test instead of Source. If I create a new source folder and marki it as such in Project Structure, this will get wiped next time `IntelliJ` refreshes the project configuration from the gradle build files. What is the more appropriate way of configuring JUnit tests in an gradle-based android project on `IntelliJ`? Which directory structure to use for this?