testing - In Android, why do I need to use androidTestCompile for the "test" sourceSet? -
so have library module wraps api, , want write tests. want import things junit , mockwebserver, test sourceset, , not androidtest one, want use former because latter cause tests run in android device or avd, not want. therefore, have in gradle file:
sourcesets { main { test { setroot('src/test') } } }
...
dependencies { ... testcompile 'junit:junit:4.12' testcompile 'com.squareup.okhttp:mockwebserver:2.4.0' }
however, not work, , instead have import dependencies androidtestcompile
ones. why this?
you should have structure this:
root module src main test
and need in build.gradle
(without setting source sets):
dependencies { // unit testing dependencies. testcompile 'junit:junit:4.12' testcompile 'com.squareup.okhttp:mockwebserver:2.4.0' }
you can check in official repo google:
- a collection of samples demonstrating different frameworks
- collection of google's android testing tools
if use unit test , instrumentation tests should have:
root module src main test androidtest
in case build.gradle should be:
dependencies { // dependencies local unit tests testcompile 'junit:junit:4.12' testcompile 'org.mockito:mockito-all:1.10.19' testcompile 'org.hamcrest:hamcrest-all:1.3' // android testing support library's runner , rules androidtestcompile 'com.android.support.test:runner:0.3' androidtestcompile 'com.android.support.test:rules:0.3' }
Comments
Post a Comment