Posts

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: 'com.android.application' android { ... defaultConfig { … testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' } } dependencies { ... // test dependency testCompile 'junit:junit:4.12' testCompile group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3' // AndroidJUnit Runner dependencies androidTestCompile 'com.android.support.test:runner:0.3' // Set this dependency to use JUnit 4 rules androidTestCompile 'com.android.support.test:rules:0.3' // Dependency conflict androidTestCompile 'com.android.support:support-annotations:22.+' } Simple test to put in src/a