Sharing resources across unit tests and instrumentation tests in Android

陌路散爱 提交于 2019-12-08 18:37:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!