title: Running unit tests of a plain Java project in Android Studio with Gradle
body: <p>In a multi-module Android project, I have a plain Java project that other Android libraries and applications depend on. I recently migrated the entire project to build using Gradle.</p>
  
  <p>I have a problem running the junit tests of the plain Java project, only in Android Studio. On the command line the tests are running fine:</p>
  
  <pre><code>./gradlew -p the-java-proj test
  </code></pre>
  
  <p>This executes the unit tests as expected, if I insert a <code>Assert.fail()</code> as a sanity check, I correctly get the expected failure.</p>
  
  <p>However, I cannot manage to run the unit tests in Android Studio. I created a run configuration to run all tests in the package, and I get this error when running:</p>
  
  <blockquote>
    <p>Error running MYTESTNAME: No junit.jar in Module 'MYMODULENAME' runtime scope</p>
  </blockquote>
  
  <p>That "runtime scope" at the end is fishy, but I don't know what I'm supposed to do with that. Here's the <code>build.gradle</code> of the project:</p>
  
  <pre><code>apply plugin: 'java'
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      testCompile 'junit:junit:4.11'
      testCompile 'org.mockito:mockito-all:1.9.5'
  }
  </code></pre>
  
  <p>This is especially puzzling because I could run unit tests fine in Android Studio before migrating to Gradle. Only now I have such problem. I also don't get friendly context menu options to run individual unit tests. And, as far as I remember, the keyboard shortcut to run unit tests in the current file used to work before, now it just pops up the run configuration chooser with no option to add new.</p>