dependency Android Tests Configure module Procedure: • create a separate “pure java” module • put the Java classes under main/ • put the Junit tests under /test
the command is run at the root of the project directory. Run all the tests for the whole project: $./gradlew test Run only the tests for the pure java module: $./gradlew :myjavamodulename:test Android Tests Run the tests
'org.robolectric:robolectric:2.3') androidTestCompile( 'junit:junit:4.12-beta-2') … } Add the dependencies Android Tests Configure build.gradle (2/2) Tell the plugin which module you test
the command is run at the root of the project directory. Run all the tests for the whole project: $./gradlew test Run only the tests for the robolectric module: $./gradlew :myrobolecticmodulename:test Android Tests Run the tests
{ ... compile 'com.android.support:support-annotations:21.0.3' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0' androidTestCompile 'com.android.support.test:testing-support-lib:0.1' } Android Tests Configure build.gradle Espresso 2.0 is now part of the Android Support Library, easy integration
the command is run at the root of the project directory. Make sure a device is connected to the workstation. Run all the instrumentation tests for the whole project: $./gradlew connectedAndroidTest Android Tests Run the tests
androidTestCompile('junit:junit:4.12-beta-2') { exclude group: 'org.hamcrest' } } packagingOptions { exclude 'META-INF/LICENSE.txt' exclude 'LICENSE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' } ./gradlew clean When nothing is working a good old clean is often the answer! Dealing with dependencies
//Avoid the test if not a Genymotion device if (!GenymotionManager.isGenymotionDevice()) return; GenymotionManager.getGenymotionManager(context) .getGps() .setLatitude(64.13367829) .setLongitude(-21.8964386); //Your tests assertEquals(view.getVisibility(), View.GONE); } Test if Genymotion device Set the GPS Position Genymotion Tools TestGPS.java Test your app there! Let’s go to Dalvik