title: Instrumented Tests in Android Studio
body: <p>I have been trying to run simple instrumented tests in Android Studio, without any success. 
  I followed the guide for <a href="https://developer.android.com/training/testing/unit-testing/local-unit-tests.html" rel="nofollow">Unit Tests</a> and it works fine. Now, I would like to tests components which are difficult to mock. 
  When I follow the <a href="https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html" rel="nofollow">guide on instrumented tests</a>, I end up with dependency errors. </p>
  
  <p>What I did: </p>
  
  <ul>
  <li><p>Install the Android Testing Support Library (Android Support Repository, rev 17).</p></li>
  <li><p>Create a directory androidTest in src. Add Java folder + package ending with "test". </p></li>
  <li>Add a simple Test class</li>
  </ul>
  
  <blockquote>
  <pre><code> @RunWith(AndroidJUnit4.class)
      public class ServerRequestInstrumentationTest {
          @Test
          public void test(){
             LogC.d("Here we go testing !");
          }
      }
  </code></pre>
  </blockquote>
  
  <ul>
  <li>Add a simple TestSuit.</li>
  </ul>
  
  <blockquote>
  <pre><code>@RunWith(Suite.class)
  @Suite.SuiteClasses({ServerRequestInstrumentationTest.class})
  public class TestSuit {
  
      public TestSuit(){}
  }
  </code></pre>
  </blockquote>
  
  <ul>
  <li>Modify my gradle file to add dependencies.</li>
  </ul>
  
  <blockquote>
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 22
      buildToolsVersion "22.0.1"
  
      defaultConfig {
          applicationId "com.mydomain.app"
          minSdkVersion 9
          targetSdkVersion 22
          versionCode 28
          versionName "2.0.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
          compileOptions {
              sourceCompatibility JavaVersion.VERSION_1_7
              targetCompatibility JavaVersion.VERSION_1_7
          }
  
      }
  
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
              lintOptions {
                  disable 'MissingTranslation'
              }
          }
      }
      sourceSets { main { java.srcDirs = ['src/main/java'] } }
  }
  
  dependencies {
      compile 'com.android.support:support-v4:22.2.0'
      compile 'com.android.support:appcompat-v7:22.2.0'
      wearApp project(':wear')
      compile project(':moreapps')
      compile project(':lib_repair')
      compile project(':bugreport')
      //testCompile 'junit:junit:4.12'
      testCompile 'org.mockito:mockito-core:1.10.19'
      androidTestCompile 'junit:junit:4.12'
      androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
      androidTestCompile 'com.android.support.test:runner:0.3'
      androidTestCompile 'com.android.support.test:rules:0.3'
  }
  </code></pre>
  </blockquote>
  
  <p>I just added the line <code>androidTestCompile 'junit:junit:4.12'</code>, otherwise the annotation <code>@RunWith(AndroidJUnit4.class)</code> wasn't recognized. 
  Now when I launch the test, I get one Gradle build error.</p>
  
  <blockquote>
    <p>Error:Execution failed for task ':app:dexDebugAndroidTest'.</p>
    
    <blockquote>
      <p>com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command
      '/usr/lib/jvm/jdkoracle/bin/java'' finished with non-zero exit value 2</p>
    </blockquote>
  </blockquote>
  
  <p>Any suggestion ? Did I miss something about the testing library ?</p>
  
  <p>Thank you</p>