title: How to share JSON files between Android Test and Unit Tests in Android
body: <p>I tried the suggestions given in the comments on this blog - <a href="http://blog.danlew.net/2015/11/02/sharing-code-between-unit-tests-and-instrumentation-tests-on-android/" rel="nofollow noreferrer">http://blog.danlew.net/2015/11/02/sharing-code-between-unit-tests-and-instrumentation-tests-on-android/</a></p>
  
  <p>but the file cannot be read by the Android tests; unit tests work perfectly fine.</p>
  
  <p>build.gradle:</p>
  
  <pre><code>sourceSets {
      String sharedTestDir = 'src/sharedTestHelpers/java'
      String sharedTestAssetDir = 'src/sharedTestHelpers/assets'
      test {
          java.srcDir sharedTestDir
          assets.srcDir sharedTestAssetDir
      }
      androidTest {
          java.srcDir sharedTestDir
          assets.srcDir sharedTestAssetDir
      }
  }
  </code></pre>
  
  <p>TestCreator class:</p>
  
  <pre><code>public class TestDataCreator {
    public static String readFromFile(String fileName) throws IOException    
    {
      return FileUtils.readFileToString(new    
      File("src/sharedTestHelpers/assets/" + fileName));
    }}
  </code></pre>
  
  <p>Project Structure:</p>
  
  <p><a href="https://i.stack.imgur.com/DspnG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DspnG.png" alt="Project structure"></a></p>
  
  <p>Any pointers?</p>