Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing resources across unit tests and instrumentation tests in Android

Now that Google has added experimental unit test support, how might one go about sharing resources across both unit tests and instrumentation test?

For example, say I have a TestUtils.java class that I want accessible in both my unit tests and my instrumentation tests. If I put it in my src/test/java folder, it will be accessible to my unit tests. If I put it in my src/androidTest/java folder, it will be accessible to my instrumentation tests. How do I make it accessible to both?

The only solution I see right now is putting it in src/debug/java, but is there a better way?

like image 960
skoush Avatar asked Mar 24 '15 22:03

skoush


1 Answers

android {  
  sourceSets {
    String sharedTestDir = 'src/sharedTest/java'
    test {
      java.srcDir sharedTestDir
    }
    androidTest {
      java.srcDir sharedTestDir
    }
  }
}
like image 133
laomo Avatar answered Nov 15 '22 01:11

laomo