title: Unit tests with Android Studio and Gradle?
body: <p>How can I add unit tests to my Android projects in Android Studio (IntelliJ) easily?</p>
  
  <p>To be more exact: I want to add a folder with test code (JUnit 4) and execute the unit tests from there using the regular installed JDK (not in an Android emulator).
  So far I added the folders 'test/java/' to my module and added 'test' as a source set and junit as a test dependency:</p>
  
  <pre><code>sourceSets {
    instrumentTest.setRoot('src/test')
  }
  
  dependencies {
    instrumentTestCompile 'junit:junit:4.+'
    // ...
  }
  </code></pre>
  
  <p>When I now select <strong>Run 'All Tests'</strong> on the test/java folder it gives me an UnsupportedOperationException.</p>
  
  <p>What am I missing? How do you run your unit tests for Android projects?</p>
  
  <p>Bonus points for a recommendation of a plugin that works like 'Infinitest' in Eclipse - where I can simply save a class and its unit test is automatically executed. :-)</p>
  
  <p>PS: I do not want to use <a href="https://github.com/JakeWharton/gradle-android-test-plugin" rel="noreferrer">https://github.com/JakeWharton/gradle-android-test-plugin</a> since that plugin seems to be deprecated already.</p>