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:

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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -