title: How to add test folders to an older Android Studio Project
body: <p>I'm having some problems adding the project structure for testing, to an older Android project in Android Studio. </p>
  
  <p>When you create a new project in Android Studio, you get the directories for testing created from start.</p>
  
  <pre><code>src/test/java - for unit testing 
  src/androidTest/java - for Android/UI testing. 
  </code></pre>
  
  <p>But our project didn't have those, since it's an older project we have migrated from Eclipse. </p>
  
  <p>I have succesfully added the directory (test) and java folder (test/java) for unit testing to our project, where the java directory is recognized as a java directory, so I can add new packages and java files. </p>
  
  <p>When I look at the packages in the Android Project view, they're listed as:</p>
  
  <pre><code>com.ourcompany.ourapp
  com.ourcompany.ourapp (test) - And here I can see my testclasses. 
  </code></pre>
  
  <p>All good so far. </p>
  
  <p>But I cannot seem add the structure for androidTest. </p>
  
  <p>If I add the directory androidTest and a javafolder called java under it, the java folder is marked as green, and I can add classes and packages. But the testpackage is not marked as a test. </p>
  
  <p>I get this result in the android project view. </p>
  
  <pre><code>com.ourcompany.ourapp
  com.ourcompany.ourapp - And here is the testclass, MainActivityTest.java
  com.ourcompany.ourapp (test)
  </code></pre>
  
  <p>When I added the androidTest/java folder, this line appeared in the build.gradle file: </p>
  
  <pre><code>android { sourceSets { main { java.srcDirs = ['src/main/java', 'src/androidTest/java/'] } } }
  </code></pre>
  
  <p>If I remove that line, then the androidTest/java folder is no longer recognized as a javafolder, and I cannot add classes/packages there anymore. And in the Android Project View, the MainActivityTest class is no longer visible at all. </p>
  
  <p>What am I missing, when it comes to adding the androidTest folders, for it to be recognized as a test folder structure? </p>
  
  <p>Is there something I need to add to the gradles file? </p>
  
  <pre><code>android {
      compileSdkVersion 21
      buildToolsVersion '22.0.1'
  
      defaultConfig {
          applicationId "com.ourcompany.ourapp"
          minSdkVersion 15
          targetSdkVersion 21
      }
  
      buildTypes {
          release {
              minifyEnabled true
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
          }
      }
  
      lintOptions {
          checkReleaseBuilds true
          abortOnError false
      }
  
      configurations.all {
          resolutionStrategy.force 'com.android.support:support-annotations:22.2.1'
      }
  
  }
  
  dependencies {
      compile 'com.android.support:support-v4:22.1.1'
      compile 'com.android.support:design:22.2.1'
      compile 'com.android.support:appcompat-v7:22.1.1'
      testCompile 'junit:junit:4.12'
      testCompile "org.mockito:mockito-core:1.+"
  }
  
  android {
      packagingOptions {
          exclude 'META-INF/DEPENDENCIES.txt'
          exclude 'META-INF/LICENSE.txt'
          exclude 'META-INF/NOTICE.txt'
          exclude 'META-INF/NOTICE'
          exclude 'META-INF/LICENSE'
          exclude 'META-INF/DEPENDENCIES'
          exclude 'META-INF/notice.txt'
          exclude 'META-INF/license.txt'
          exclude 'META-INF/dependencies.txt'
          exclude 'META-INF/LGPL2.1'
      }
  }
  </code></pre>