Showing posts from August, 2015

Add Android unit test to existing android studio project

Here I'm talking about tests that needs Emulator or a device to run, not pure java unit test. For example for testing a provider. The test example is pure java though but it is a simple proof of concept.

Add the following in your build.gradle

apply plugin: '' android { ... defaultConfig { … testInstrumentationRunner '' } } dependencies { ... // test dependency testCompile 'junit:junit:4.12' testCompile group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3' // AndroidJUnit Runner dependencies androidTestCompile '' // Set this dependency to use JUnit 4 rules androidTestCompile '' // Dependency conflict androidTestCompile '' }
Simple test to put in src/androidT…