问题
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?
回答1:
android {
sourceSets {
String sharedTestDir = 'src/sharedTest/java'
test {
java.srcDir sharedTestDir
}
androidTest {
java.srcDir sharedTestDir
}
}
}
来源:https://stackoverflow.com/questions/29243787/sharing-resources-across-unit-tests-and-instrumentation-tests-in-android