SlideShare a Scribd company logo
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 http://www.flickr.com/photos/johnhaydon/5161176888/
How to setup unit testing in Android Studio
Testing
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
What changed at the slides
Changelog
v.1.0.1 Removed duplicate slide
v.1.0.0 Initial version
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
A tiny piece of structure
The presentation
Part 1: General project setup
Part 2: IDE integration
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Part 1: General project setup
The easy part
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Expecting the default project structure of Android Studio / Gradle
Project structure
├── build.gradle
└── app
├── build.gradle
└── src
└── main
├── AndroidManifest.xml
├── java
└── res
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Robolectric and jUnit 4 to app/build.gradle
Dependencies
dependencies {
androidTestCompile 'org.robolectric:robolectric:2.+'
androidTestCompile 'junit:junit:4.+'
}
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Add novoda/robolectric-plugin to /build.gradle
Gradle plugin
buildscript {
repositories {
mavenCentral()
// Add this repository:
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
// And this dependency:
classpath 'com.novoda.gradle:robolectric-plugin:0.0.1-SNAPSHOT'
}
}
allprojects {
repositories {
mavenCentral()
// And finally this repository again.
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
}
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Apply the plugin to app/build.gradle
Gradle plugin
apply plugin: 'robolectric'
Now sync ...
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Create a test folder: app/src/test/java/com/example/app/test
Create a test
package com.example.app.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import static org.junit.Assert.*;
@RunWith(RobolectricTestRunner.class)
public class RoboTest {
@Test
public void testTrueIsTrue() throws Exception {
assertEquals(true, true);
}
}
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Android Studio does not recognize app/src/test/java as source directory
Run the test (from the shell)
$ ./gradlew robolectric
Should look like this …
...
:app:assemble
:app:compileRobolectricJava
:app:processRobolectricResources UP-TO-DATE
:app:robolectricClasses
:app:robolectric
BUILD SUCCESSFUL
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
The confusing part
Part 2: IDE integration
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Add a task to app/build.gradle
Register the test folder
task addTest {
description "Registers the test folder in the .iml file so Java tooling works."
def src = ['src/test/java']
def file = file("app.iml") // Must match module file name
doLast {
try {
def parsedXml = (new XmlParser()).parse(file)
def node = parsedXml.component[1].content[0]
src.each {
def path = 'file://$MODULE_DIR$/' + "${it}"
def set = node.find { it.@url == path }
if (set == null) {
new Node(node, 'sourceFolder',
['url': 'file://$MODULE_DIR$/' + "${it}", 'isTestSource': "true"])
def writer = new StringWriter()
new XmlNodePrinter(new PrintWriter(writer)).print(parsedXml)
file.text = writer.toString()
}
}
} catch (FileNotFoundException e) {
// nop, iml not found
}
}
}
// always do the addtest on prebuild
gradle.projectsEvaluated {
preBuild.dependsOn(addTest)
}
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
The test folder is recognized by Android Studio
Register the test folder
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Pick it from the context menu ...
Run All Tests
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Test were not started
Failed to run tests
!!! JUnit version 3.8 or later expected:
java.lang.RuntimeException: Stub!
at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
at junit.textui.TestRunner.<init>(TestRunner.java:54)
at junit.textui.TestRunner.<init>(TestRunner.java:48)
at junit.textui.TestRunner.<init>(TestRunner.java:41)
Process finished with exit code 253
Copy everything printed to the output!
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Before ...
Some text editor work
/usr/lib/jvm/jdk1.7.0/bin/java -ea -Didea.launcher.port=7532 -Didea.launcher.bin.path=/opt/android-studio/bin -Dfile.encoding=UTF-8 -classpath
/opt/android-studio/lib/idea_rt.jar:/opt/android-studio/plugins/junit/lib/junit-rt.jar:/media/data/SDKs/android-sdk-linux_x86/platforms/android-19/android.jar:/
media/data/SDKs/android-sdk-linux_x86/platforms/android-19/data/res:/media/data/SDKs/android-sdk-linux_x86/tools/support/annotations.jar:/media/data/Development
_Ubuntu/TestRobolectricHome/app/build/classes/debug:/home/tobias/.gradle/caches/modules-2/files-2.1/classworlds/classworlds/1.1-alpha-2/5adf2e681c57d7f48038b602
f3ca2254ee82d47/classworlds-1.1-alpha-2.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.codehaus.plexus/plexus-utils/1.5.15/c689598ce1eb94c304817877ed15
911099972526/plexus-utils-1.5.15.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/1.3/dc13ae4faca6df981fc7aeb5a522d9db446d5d50/objene
sis-1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-artifact-manager/2.2.1/ec355b913c34d37080810f98e3f51abecbe1572b/maven-artifac
t-manager-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/nekohtml/nekohtml/1.9.6.2/2d960be7b62ae6622dbbbe49ab4ffdc609f85c80/nekohtml-1.9.6.2.jar:/hom
e/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-tree/4.1/51085abcc4cb6c6e1cb5551e6f999eb8e31c5b2d/asm-tree-4.1.jar:/home/tobias/.gradle/caches/modul
es-2/files-2.1/org.ow2.asm/asm/4.1/ad568238ee36a820bd6c6806807e8a14ea34684d/asm-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.xerial/sqlite-jdbc/3
.7.2/7a3d67f00508d3881650579f7f228c61bfc1b196/sqlite-jdbc-3.7.2.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant/1.8.0/7b456ca6b93900f96e5
8cc8371f03d90a9c1c8d1/ant-1.8.0.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-repository-metadata/2.2.1/98f0c07fcf1eeb213bef8d9316a
9935184084b06/maven-repository-metadata-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-ant-tasks/2.1.3/b09be554228d66d208e5fef
5266844aacf443abc/maven-ant-tasks-2.1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-error-diagnostics/2.2.1/e81bb342d7d172f23d108
dc8fa979a1facdcde8e/maven-error-diagnostics-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-http-lightweight/1.0-beta-6/b
3815078570c3b1f0667e123d59717c6b726c6c2/wagon-http-lightweight-1.0-beta-6.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.3/fd
32786786e2adb664d5ecc965da47629dca14ba/commons-codec-1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-http-shared/1.0-beta-6
/ccd70d7e0d8c085e648a83f072da06ca9a53be94/wagon-http-shared-1.0-beta-6.jar:/media/data/Development_Ubuntu/TestRobolectricHome/app/build/exploded-aar/com.android
.support/appcompat-v7/19.0.1/res:/media/data/Development_Ubuntu/TestRobolectricHome/app/build/exploded-aar/com.android.support/appcompat-v7/19.0.1/classes.jar:/
home/tobias/.gradle/caches/modules-2/files-2.1/org.robolectric/robolectric/2.2/af902024b55e3b41732a7d9f41c32f90c065be2f/robolectric-2.2.jar:/home/tobias/.gradle
/caches/modules-2/files-2.1/org.codehaus.plexus/plexus-container-default/1.0-alpha-9-stable-1/94aea3010e250a334d9dab7f591114cd6c767458/plexus-container-default-
1.0-alpha-9-stable-1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/backport-util-concurrent/backport-util-concurrent/3.1/682f7ac17fed79e92f8e87d8455192b63
376347b/backport-util-concurrent-3.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-plugin-registry/2.2.1/72a24b7775649af78f3986b5aa
7eb354b9674cfd/maven-plugin-registry-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-settings/2.2.1/2236ffe71fa5f78ce42b0f5fc22
c54ed45f14294/maven-settings-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-file/1.0-beta-6/6c53633505460caf49d2660de1e2
4744d915afb9/wagon-file-1.0-beta-6.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/com.ximpleware/vtd-xml/2.11/ee5bcf62c1acf76434ee9f1c67a840bafef72a6d/vtd-
xml-2.11.jar:/media/data/SDKs/android-sdk-linux_x86/extras/android/m2repository/com/android/support/support-v4/19.0.1/support-v4-19.0.1.jar:/home/tobias/.gradle
/caches/modules-2/files-2.1/org.ow2.asm/asm-commons/4.1/f8b86f4ee6e02082f63a658e00eb5506821253c6/asm-commons-4.1.jar:/home/tobias/.gradle/caches/modules-2/files
-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/a
sm-analysis/4.1/73401033069e4714f57b60aeae02f97210aaa64e/asm-analysis-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/junit/junit/4.11/4e031bb61df09069a
eb2bffb4019e7a5034a4ee0/junit-4.11.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-artifact/2.2.1/23600f790d4dab2cb965419eaa982e3e84c
428f8/maven-artifact-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-profile/2.2.1/3950071587027e5086e9c395574a60650c432738/mav
en-profile-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/com.google.android/support-v4/r7/24d0f6da34c3a2bfcf736ab42d51c91ac821ee22/support-v4-r7.jar
:/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-util/4.1/6344065cb0f94e2b930a95e6656e040ebc11df08/asm-util-4.1.jar:/home/tobias/.gradle/caches/
modules-2/files-2.1/org.apache.maven/maven-model/2.2.1/c0a1c17436ec3ff5a56207c031d82277b4250a29/maven-model-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/file
s-2.1/org.easytesting/fest-util/1.2.5/c4a8d7305b23b8d043be12c979813b096df11f44/fest-util-1.2.5.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.an
t/ant-launcher/1.8.0/8b53ba16fa62fb1034da8f1de200ddc407c8381/ant-launcher-1.8.0.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.codehaus.plexus/plexus-i
nterpolation/1.11/ad9dddff6043194904ad1d2c00ff1d003c3915f7/plexus-interpolation-1.11.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.easytesting/fest-re
flect/1.4.1/2b92d5275e92a49e16c7ce6bd7e46b9080db0530/fest-reflect-1.4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-project/2.2.1
/8239e98c16f641d55a4ad0e0bab0aee3aff8933f/maven-project-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-provider-api/1.0-
beta-6/3f952e0282ae77ae59851d96bb18015e520b6208/wagon-provider-api-1.0-beta-6.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/nekohtml/xercesMinimal/1.9.6.2
/d1c5e063683a0e6f77cd5f051a9d4af48346fa6/xercesMinimal-1.9.6.2.jar ...
Remove everything before -classpath
Find juni part and prepend it
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
After ...
Some text editor work
-classpath
/home/tobias/.gradle/caches/modules-2/files-2.1/junit/junit/4.11/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar:/opt/android-studio/lib/idea_rt.jar:/op
t/android-studio/plugins/junit/lib/junit-rt.jar:/media/data/SDKs/android-sdk-linux_x86/platforms/android-19/android.jar:/media/data/SDKs/android-sdk-linux_x86/p
latforms/android-19/data/res:/media/data/SDKs/android-sdk-linux_x86/tools/support/annotations.jar:/media/data/Development_Ubuntu/TestRobolectricHome/app/build/c
lasses/debug:/home/tobias/.gradle/caches/modules-2/files-2.1/classworlds/classworlds/1.1-alpha-2/5adf2e681c57d7f48038b602f3ca2254ee82d47/classworlds-1.1-alpha-2
.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.codehaus.plexus/plexus-utils/1.5.15/c689598ce1eb94c304817877ed15911099972526/plexus-utils-1.5.15.jar:/h
ome/tobias/.gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/1.3/dc13ae4faca6df981fc7aeb5a522d9db446d5d50/objenesis-1.3.jar:/home/tobias/.gradle/caches
/modules-2/files-2.1/org.apache.maven/maven-artifact-manager/2.2.1/ec355b913c34d37080810f98e3f51abecbe1572b/maven-artifact-manager-2.2.1.jar:/home/tobias/.gradl
e/caches/modules-2/files-2.1/nekohtml/nekohtml/1.9.6.2/2d960be7b62ae6622dbbbe49ab4ffdc609f85c80/nekohtml-1.9.6.2.jar:/home/tobias/.gradle/caches/modules-2/files
-2.1/org.ow2.asm/asm-tree/4.1/51085abcc4cb6c6e1cb5551e6f999eb8e31c5b2d/asm-tree-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm/4.1/ad56
8238ee36a820bd6c6806807e8a14ea34684d/asm-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.xerial/sqlite-jdbc/3.7.2/7a3d67f00508d3881650579f7f228c61bf
c1b196/sqlite-jdbc-3.7.2.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant/1.8.0/7b456ca6b93900f96e58cc8371f03d90a9c1c8d1/ant-1.8.0.jar:/ho
me/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-repository-metadata/2.2.1/98f0c07fcf1eeb213bef8d9316a9935184084b06/maven-repository-metadata
-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-ant-tasks/2.1.3/b09be554228d66d208e5fef5266844aacf443abc/maven-ant-tasks-2.1.3
.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-error-diagnostics/2.2.1/e81bb342d7d172f23d108dc8fa979a1facdcde8e/maven-error-diagnos
tics-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-http-lightweight/1.0-beta-6/b3815078570c3b1f0667e123d59717c6b726c6c2
/wagon-http-lightweight-1.0-beta-6.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.3/fd32786786e2adb664d5ecc965da47629dca14ba/
commons-codec-1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-http-shared/1.0-beta-6/ccd70d7e0d8c085e648a83f072da06ca9a53be
94/wagon-http-shared-1.0-beta-6.jar:/media/data/Development_Ubuntu/TestRobolectricHome/app/build/exploded-aar/com.android.support/appcompat-v7/19.0.1/res:/media
/data/Development_Ubuntu/TestRobolectricHome/app/build/exploded-aar/com.android.support/appcompat-v7/19.0.1/classes.jar:/home/tobias/.gradle/caches/modules-2/fi
les-2.1/org.robolectric/robolectric/2.2/af902024b55e3b41732a7d9f41c32f90c065be2f/robolectric-2.2.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.codehau
s.plexus/plexus-container-default/1.0-alpha-9-stable-1/94aea3010e250a334d9dab7f591114cd6c767458/plexus-container-default-1.0-alpha-9-stable-1.jar:/home/tobias/.
gradle/caches/modules-2/files-2.1/backport-util-concurrent/backport-util-concurrent/3.1/682f7ac17fed79e92f8e87d8455192b63376347b/backport-util-concurrent-3.1.ja
r:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-plugin-registry/2.2.1/72a24b7775649af78f3986b5aa7eb354b9674cfd/maven-plugin-registry-2.
2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-settings/2.2.1/2236ffe71fa5f78ce42b0f5fc22c54ed45f14294/maven-settings-2.2.1.jar:
/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-file/1.0-beta-6/6c53633505460caf49d2660de1e24744d915afb9/wagon-file-1.0-beta-6.jar:
/home/tobias/.gradle/caches/modules-2/files-2.1/com.ximpleware/vtd-xml/2.11/ee5bcf62c1acf76434ee9f1c67a840bafef72a6d/vtd-xml-2.11.jar:/media/data/SDKs/android-s
dk-linux_x86/extras/android/m2repository/com/android/support/support-v4/19.0.1/support-v4-19.0.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm
/asm-commons/4.1/f8b86f4ee6e02082f63a658e00eb5506821253c6/asm-commons-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a
25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-analysis/4.1/73401033069e4714f57b60a
eae02f97210aaa64e/asm-analysis-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-artifact/2.2.1/23600f790d4dab2cb965419eaa982e3e84c
428f8/maven-artifact-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-profile/2.2.1/3950071587027e5086e9c395574a60650c432738/mav
en-profile-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/com.google.android/support-v4/r7/24d0f6da34c3a2bfcf736ab42d51c91ac821ee22/support-v4-r7.jar
:/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-util/4.1/6344065cb0f94e2b930a95e6656e040ebc11df08/asm-util-4.1.jar:/home/tobias/.gradle/caches/
modules-2/files-2.1/org.apache.maven/maven-model/2.2.1/c0a1c17436ec3ff5a56207c031d82277b4250a29/maven-model-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/file
s-2.1/org.easytesting/fest-util/1.2.5/c4a8d7305b23b8d043be12c979813b096df11f44/fest-util-1.2.5.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.an
t/ant-launcher/1.8.0/8b53ba16fa62fb1034da8f1de200ddc407c8381/ant-launcher-1.8.0.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.codehaus.plexus/plexus-i
nterpolation/1.11/ad9dddff6043194904ad1d2c00ff1d003c3915f7/plexus-interpolation-1.11.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.easytesting/fest-re
flect/1.4.1/2b92d5275e92a49e16c7ce6bd7e46b9080db0530/fest-reflect-1.4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-project/2.2.1
/8239e98c16f641d55a4ad0e0bab0aee3aff8933f/maven-project-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-provider-api/1.0-
beta-6/3f952e0282ae77ae59851d96bb18015e520b6208/wagon-provider-api-1.0-beta-6.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/nekohtml/xercesMinimal/1.9.6.2
/d1c5e063683a0e6f77cd5f051a9d4af48346fa6/xercesMinimal-1.9.6.2.jar ...
The juni part is at the beginning now
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Classpath goes into VM options
Setup run configuration
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Create a Gradle task
Generate Robolectric classes
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Add to JUnit configuration, Before launch
Launch Robolectric configuration
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1
Big thanks to Ilkka Laukkanen
Credits
Further information:
http://blog.futurice.com/android_unit_testing_in_ides_and_ci_environments
Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 http://www.flickr.com/photos/dopey/123646856/
Questions

More Related Content

ODP
Unit Test Android Without Going Bald
PDF
Testing on Android
PDF
Learn How to Unit Test Your Android Application (with Robolectric)
PDF
Unit testing and Android
PPTX
Android testing
PPTX
Android testing
PPTX
Introduction to android studio 2.0 and data binding library
PPTX
Exploring the power of Gradle in android studio - Basics & Beyond
Unit Test Android Without Going Bald
Testing on Android
Learn How to Unit Test Your Android Application (with Robolectric)
Unit testing and Android
Android testing
Android testing
Introduction to android studio 2.0 and data binding library
Exploring the power of Gradle in android studio - Basics & Beyond

What's hot (20)

PDF
Android studio
PDF
Efficient JavaScript Unit Testing, JavaOne China 2013
PDF
Efficient JavaScript Unit Testing, May 2012
PPTX
[AnDevCon 2016] Mutation Testing for Android
PPTX
Testing android apps with espresso
PDF
Effective Android Development. UA Mobile 2016.
PDF
Android testing part i
PPT
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
ODP
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
PPTX
不只自動化而且更敏捷的Android開發工具 gradle
PPTX
Testing for Android: When, Where, and How to Successfully Use Test Automation
PPTX
WindowTester PRO
PPTX
Apache Maven - eXo VN office presentation
PDF
Android Testing: An Overview
PDF
ScalaUA - distage: Staged Dependency Injection
PDF
Scala, Functional Programming and Team Productivity
PDF
Hyper-pragmatic Pure FP testing with distage-testkit
PDF
Implementing Quality on a Java Project
PDF
[Ultracode Munich #4] Short introduction to the new Android build system incl...
PDF
Vietnam qa meetup
Android studio
Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, May 2012
[AnDevCon 2016] Mutation Testing for Android
Testing android apps with espresso
Effective Android Development. UA Mobile 2016.
Android testing part i
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
[EclipseCon NA 2014] Integration tests for RCP made easy with SWTBot and Tycho
不只自動化而且更敏捷的Android開發工具 gradle
Testing for Android: When, Where, and How to Successfully Use Test Automation
WindowTester PRO
Apache Maven - eXo VN office presentation
Android Testing: An Overview
ScalaUA - distage: Staged Dependency Injection
Scala, Functional Programming and Team Productivity
Hyper-pragmatic Pure FP testing with distage-testkit
Implementing Quality on a Java Project
[Ultracode Munich #4] Short introduction to the new Android build system incl...
Vietnam qa meetup
Ad

Viewers also liked (20)

PDF
Gradle talk, Javarsovia 2010
KEY
Introduction to android testing
PDF
Inside Android Testing
PDF
Testing Android
PDF
Android testing
PDF
Android Building, Testing and reversing
PDF
Testing on Android
PDF
Lecture 5: Storage: Saving Data Database, Files & Preferences
PDF
Android Lesson 3 - Intent
PPTX
Creating the first app with android studio
PPTX
Android seminar ppt
DOC
My Project Report Documentation with Abstract & Snapshots
PPT
PDF
Mobile app works
PDF
Android Development - Process & Tools
PPTX
Gradle 和 Android Studio --- Jason Ko
PPTX
Android app fundamentals
PDF
Android Fundamentals
PDF
Android Fundamentals - Day 2
Gradle talk, Javarsovia 2010
Introduction to android testing
Inside Android Testing
Testing Android
Android testing
Android Building, Testing and reversing
Testing on Android
Lecture 5: Storage: Saving Data Database, Files & Preferences
Android Lesson 3 - Intent
Creating the first app with android studio
Android seminar ppt
My Project Report Documentation with Abstract & Snapshots
Mobile app works
Android Development - Process & Tools
Gradle 和 Android Studio --- Jason Ko
Android app fundamentals
Android Fundamentals
Android Fundamentals - Day 2
Ad

Similar to How to setup unit testing in Android Studio (20)

PDF
Android Meetup Slovenija #3 - Testing with Robolectric by Ivan Kust
PDF
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
PDF
Agile Android
PDF
#BABBQAmsterdam The other Android getting started guide: Gradle power
PDF
Guide to the jungle of testing frameworks
PDF
Introduction to Robotium
PDF
Android TDD
PDF
Robotium - sampath
PDF
Testing and Building Android
PDF
Amplify - TDD on Android with Robolectric
PDF
Android build process (1)
PDF
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
PPTX
Android developer's toolbox
PPTX
Unit Testing Android Applications
PDF
Gradle as cmd
PPTX
Android Testing
PDF
Writing Android Libraries
PPTX
Robolectric Adventure
PDF
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Android Meetup Slovenija #3 - Testing with Robolectric by Ivan Kust
Infinum Android Talks #17 - Testing your Android applications by Ivan Kust
Agile Android
#BABBQAmsterdam The other Android getting started guide: Gradle power
Guide to the jungle of testing frameworks
Introduction to Robotium
Android TDD
Robotium - sampath
Testing and Building Android
Amplify - TDD on Android with Robolectric
Android build process (1)
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Android developer's toolbox
Unit Testing Android Applications
Gradle as cmd
Android Testing
Writing Android Libraries
Robolectric Adventure
Unit & Automation Testing in Android - Stanislav Gatsev, Melon

More from tobiaspreuss (7)

PDF
State of EventFahrplan 2021 - NO/WHERE edition
PDF
State of EventFahrplan 2021
PDF
Getting started with building your own standalone Gradle plugin
PDF
35C3: EventFahrplan - Lightning Talk - Day 2
PDF
CycleHack 2017 Berlin - How to continue
PDF
Wo ist Markt?
PDF
WhereWhat
State of EventFahrplan 2021 - NO/WHERE edition
State of EventFahrplan 2021
Getting started with building your own standalone Gradle plugin
35C3: EventFahrplan - Lightning Talk - Day 2
CycleHack 2017 Berlin - How to continue
Wo ist Markt?
WhereWhat

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Institutional Correction lecture only . . .
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Business Ethics Teaching Materials for college
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Cell Structure & Organelles in detailed.
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Pharma ospi slides which help in ospi learning
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Week 4 Term 3 Study Techniques revisited.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Insiders guide to clinical Medicine.pdf
Final Presentation General Medicine 03-08-2024.pptx
Institutional Correction lecture only . . .
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Microbial diseases, their pathogenesis and prophylaxis
FourierSeries-QuestionsWithAnswers(Part-A).pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Business Ethics Teaching Materials for college
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPH.pptx obstetrics and gynecology in nursing
Complications of Minimal Access Surgery at WLH
Cell Structure & Organelles in detailed.
01-Introduction-to-Information-Management.pdf
Pharma ospi slides which help in ospi learning

How to setup unit testing in Android Studio

  • 1. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 http://www.flickr.com/photos/johnhaydon/5161176888/ How to setup unit testing in Android Studio Testing
  • 2. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 What changed at the slides Changelog v.1.0.1 Removed duplicate slide v.1.0.0 Initial version
  • 3. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 A tiny piece of structure The presentation Part 1: General project setup Part 2: IDE integration
  • 4. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Part 1: General project setup The easy part
  • 5. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Expecting the default project structure of Android Studio / Gradle Project structure ├── build.gradle └── app ├── build.gradle └── src └── main ├── AndroidManifest.xml ├── java └── res
  • 6. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Robolectric and jUnit 4 to app/build.gradle Dependencies dependencies { androidTestCompile 'org.robolectric:robolectric:2.+' androidTestCompile 'junit:junit:4.+' }
  • 7. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Add novoda/robolectric-plugin to /build.gradle Gradle plugin buildscript { repositories { mavenCentral() // Add this repository: maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } } dependencies { classpath 'com.android.tools.build:gradle:0.8.+' // And this dependency: classpath 'com.novoda.gradle:robolectric-plugin:0.0.1-SNAPSHOT' } } allprojects { repositories { mavenCentral() // And finally this repository again. maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } } }
  • 8. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Apply the plugin to app/build.gradle Gradle plugin apply plugin: 'robolectric' Now sync ...
  • 9. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Create a test folder: app/src/test/java/com/example/app/test Create a test package com.example.app.test; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import static org.junit.Assert.*; @RunWith(RobolectricTestRunner.class) public class RoboTest { @Test public void testTrueIsTrue() throws Exception { assertEquals(true, true); } }
  • 10. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Android Studio does not recognize app/src/test/java as source directory Run the test (from the shell) $ ./gradlew robolectric Should look like this … ... :app:assemble :app:compileRobolectricJava :app:processRobolectricResources UP-TO-DATE :app:robolectricClasses :app:robolectric BUILD SUCCESSFUL
  • 11. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 The confusing part Part 2: IDE integration
  • 12. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Add a task to app/build.gradle Register the test folder task addTest { description "Registers the test folder in the .iml file so Java tooling works." def src = ['src/test/java'] def file = file("app.iml") // Must match module file name doLast { try { def parsedXml = (new XmlParser()).parse(file) def node = parsedXml.component[1].content[0] src.each { def path = 'file://$MODULE_DIR$/' + "${it}" def set = node.find { it.@url == path } if (set == null) { new Node(node, 'sourceFolder', ['url': 'file://$MODULE_DIR$/' + "${it}", 'isTestSource': "true"]) def writer = new StringWriter() new XmlNodePrinter(new PrintWriter(writer)).print(parsedXml) file.text = writer.toString() } } } catch (FileNotFoundException e) { // nop, iml not found } } } // always do the addtest on prebuild gradle.projectsEvaluated { preBuild.dependsOn(addTest) }
  • 13. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 The test folder is recognized by Android Studio Register the test folder
  • 14. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Pick it from the context menu ... Run All Tests
  • 15. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Test were not started Failed to run tests !!! JUnit version 3.8 or later expected: java.lang.RuntimeException: Stub! at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5) at junit.textui.TestRunner.<init>(TestRunner.java:54) at junit.textui.TestRunner.<init>(TestRunner.java:48) at junit.textui.TestRunner.<init>(TestRunner.java:41) Process finished with exit code 253 Copy everything printed to the output!
  • 16. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Before ... Some text editor work /usr/lib/jvm/jdk1.7.0/bin/java -ea -Didea.launcher.port=7532 -Didea.launcher.bin.path=/opt/android-studio/bin -Dfile.encoding=UTF-8 -classpath /opt/android-studio/lib/idea_rt.jar:/opt/android-studio/plugins/junit/lib/junit-rt.jar:/media/data/SDKs/android-sdk-linux_x86/platforms/android-19/android.jar:/ media/data/SDKs/android-sdk-linux_x86/platforms/android-19/data/res:/media/data/SDKs/android-sdk-linux_x86/tools/support/annotations.jar:/media/data/Development _Ubuntu/TestRobolectricHome/app/build/classes/debug:/home/tobias/.gradle/caches/modules-2/files-2.1/classworlds/classworlds/1.1-alpha-2/5adf2e681c57d7f48038b602 f3ca2254ee82d47/classworlds-1.1-alpha-2.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.codehaus.plexus/plexus-utils/1.5.15/c689598ce1eb94c304817877ed15 911099972526/plexus-utils-1.5.15.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/1.3/dc13ae4faca6df981fc7aeb5a522d9db446d5d50/objene sis-1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-artifact-manager/2.2.1/ec355b913c34d37080810f98e3f51abecbe1572b/maven-artifac t-manager-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/nekohtml/nekohtml/1.9.6.2/2d960be7b62ae6622dbbbe49ab4ffdc609f85c80/nekohtml-1.9.6.2.jar:/hom e/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-tree/4.1/51085abcc4cb6c6e1cb5551e6f999eb8e31c5b2d/asm-tree-4.1.jar:/home/tobias/.gradle/caches/modul es-2/files-2.1/org.ow2.asm/asm/4.1/ad568238ee36a820bd6c6806807e8a14ea34684d/asm-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.xerial/sqlite-jdbc/3 .7.2/7a3d67f00508d3881650579f7f228c61bfc1b196/sqlite-jdbc-3.7.2.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant/1.8.0/7b456ca6b93900f96e5 8cc8371f03d90a9c1c8d1/ant-1.8.0.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-repository-metadata/2.2.1/98f0c07fcf1eeb213bef8d9316a 9935184084b06/maven-repository-metadata-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-ant-tasks/2.1.3/b09be554228d66d208e5fef 5266844aacf443abc/maven-ant-tasks-2.1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-error-diagnostics/2.2.1/e81bb342d7d172f23d108 dc8fa979a1facdcde8e/maven-error-diagnostics-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-http-lightweight/1.0-beta-6/b 3815078570c3b1f0667e123d59717c6b726c6c2/wagon-http-lightweight-1.0-beta-6.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.3/fd 32786786e2adb664d5ecc965da47629dca14ba/commons-codec-1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-http-shared/1.0-beta-6 /ccd70d7e0d8c085e648a83f072da06ca9a53be94/wagon-http-shared-1.0-beta-6.jar:/media/data/Development_Ubuntu/TestRobolectricHome/app/build/exploded-aar/com.android .support/appcompat-v7/19.0.1/res:/media/data/Development_Ubuntu/TestRobolectricHome/app/build/exploded-aar/com.android.support/appcompat-v7/19.0.1/classes.jar:/ home/tobias/.gradle/caches/modules-2/files-2.1/org.robolectric/robolectric/2.2/af902024b55e3b41732a7d9f41c32f90c065be2f/robolectric-2.2.jar:/home/tobias/.gradle /caches/modules-2/files-2.1/org.codehaus.plexus/plexus-container-default/1.0-alpha-9-stable-1/94aea3010e250a334d9dab7f591114cd6c767458/plexus-container-default- 1.0-alpha-9-stable-1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/backport-util-concurrent/backport-util-concurrent/3.1/682f7ac17fed79e92f8e87d8455192b63 376347b/backport-util-concurrent-3.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-plugin-registry/2.2.1/72a24b7775649af78f3986b5aa 7eb354b9674cfd/maven-plugin-registry-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-settings/2.2.1/2236ffe71fa5f78ce42b0f5fc22 c54ed45f14294/maven-settings-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-file/1.0-beta-6/6c53633505460caf49d2660de1e2 4744d915afb9/wagon-file-1.0-beta-6.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/com.ximpleware/vtd-xml/2.11/ee5bcf62c1acf76434ee9f1c67a840bafef72a6d/vtd- xml-2.11.jar:/media/data/SDKs/android-sdk-linux_x86/extras/android/m2repository/com/android/support/support-v4/19.0.1/support-v4-19.0.1.jar:/home/tobias/.gradle /caches/modules-2/files-2.1/org.ow2.asm/asm-commons/4.1/f8b86f4ee6e02082f63a658e00eb5506821253c6/asm-commons-4.1.jar:/home/tobias/.gradle/caches/modules-2/files -2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/a sm-analysis/4.1/73401033069e4714f57b60aeae02f97210aaa64e/asm-analysis-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/junit/junit/4.11/4e031bb61df09069a eb2bffb4019e7a5034a4ee0/junit-4.11.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-artifact/2.2.1/23600f790d4dab2cb965419eaa982e3e84c 428f8/maven-artifact-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-profile/2.2.1/3950071587027e5086e9c395574a60650c432738/mav en-profile-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/com.google.android/support-v4/r7/24d0f6da34c3a2bfcf736ab42d51c91ac821ee22/support-v4-r7.jar :/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-util/4.1/6344065cb0f94e2b930a95e6656e040ebc11df08/asm-util-4.1.jar:/home/tobias/.gradle/caches/ modules-2/files-2.1/org.apache.maven/maven-model/2.2.1/c0a1c17436ec3ff5a56207c031d82277b4250a29/maven-model-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/file s-2.1/org.easytesting/fest-util/1.2.5/c4a8d7305b23b8d043be12c979813b096df11f44/fest-util-1.2.5.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.an t/ant-launcher/1.8.0/8b53ba16fa62fb1034da8f1de200ddc407c8381/ant-launcher-1.8.0.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.codehaus.plexus/plexus-i nterpolation/1.11/ad9dddff6043194904ad1d2c00ff1d003c3915f7/plexus-interpolation-1.11.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.easytesting/fest-re flect/1.4.1/2b92d5275e92a49e16c7ce6bd7e46b9080db0530/fest-reflect-1.4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-project/2.2.1 /8239e98c16f641d55a4ad0e0bab0aee3aff8933f/maven-project-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-provider-api/1.0- beta-6/3f952e0282ae77ae59851d96bb18015e520b6208/wagon-provider-api-1.0-beta-6.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/nekohtml/xercesMinimal/1.9.6.2 /d1c5e063683a0e6f77cd5f051a9d4af48346fa6/xercesMinimal-1.9.6.2.jar ... Remove everything before -classpath Find juni part and prepend it
  • 17. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 After ... Some text editor work -classpath /home/tobias/.gradle/caches/modules-2/files-2.1/junit/junit/4.11/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar:/opt/android-studio/lib/idea_rt.jar:/op t/android-studio/plugins/junit/lib/junit-rt.jar:/media/data/SDKs/android-sdk-linux_x86/platforms/android-19/android.jar:/media/data/SDKs/android-sdk-linux_x86/p latforms/android-19/data/res:/media/data/SDKs/android-sdk-linux_x86/tools/support/annotations.jar:/media/data/Development_Ubuntu/TestRobolectricHome/app/build/c lasses/debug:/home/tobias/.gradle/caches/modules-2/files-2.1/classworlds/classworlds/1.1-alpha-2/5adf2e681c57d7f48038b602f3ca2254ee82d47/classworlds-1.1-alpha-2 .jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.codehaus.plexus/plexus-utils/1.5.15/c689598ce1eb94c304817877ed15911099972526/plexus-utils-1.5.15.jar:/h ome/tobias/.gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/1.3/dc13ae4faca6df981fc7aeb5a522d9db446d5d50/objenesis-1.3.jar:/home/tobias/.gradle/caches /modules-2/files-2.1/org.apache.maven/maven-artifact-manager/2.2.1/ec355b913c34d37080810f98e3f51abecbe1572b/maven-artifact-manager-2.2.1.jar:/home/tobias/.gradl e/caches/modules-2/files-2.1/nekohtml/nekohtml/1.9.6.2/2d960be7b62ae6622dbbbe49ab4ffdc609f85c80/nekohtml-1.9.6.2.jar:/home/tobias/.gradle/caches/modules-2/files -2.1/org.ow2.asm/asm-tree/4.1/51085abcc4cb6c6e1cb5551e6f999eb8e31c5b2d/asm-tree-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm/4.1/ad56 8238ee36a820bd6c6806807e8a14ea34684d/asm-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.xerial/sqlite-jdbc/3.7.2/7a3d67f00508d3881650579f7f228c61bf c1b196/sqlite-jdbc-3.7.2.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant/1.8.0/7b456ca6b93900f96e58cc8371f03d90a9c1c8d1/ant-1.8.0.jar:/ho me/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-repository-metadata/2.2.1/98f0c07fcf1eeb213bef8d9316a9935184084b06/maven-repository-metadata -2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-ant-tasks/2.1.3/b09be554228d66d208e5fef5266844aacf443abc/maven-ant-tasks-2.1.3 .jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-error-diagnostics/2.2.1/e81bb342d7d172f23d108dc8fa979a1facdcde8e/maven-error-diagnos tics-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-http-lightweight/1.0-beta-6/b3815078570c3b1f0667e123d59717c6b726c6c2 /wagon-http-lightweight-1.0-beta-6.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.3/fd32786786e2adb664d5ecc965da47629dca14ba/ commons-codec-1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-http-shared/1.0-beta-6/ccd70d7e0d8c085e648a83f072da06ca9a53be 94/wagon-http-shared-1.0-beta-6.jar:/media/data/Development_Ubuntu/TestRobolectricHome/app/build/exploded-aar/com.android.support/appcompat-v7/19.0.1/res:/media /data/Development_Ubuntu/TestRobolectricHome/app/build/exploded-aar/com.android.support/appcompat-v7/19.0.1/classes.jar:/home/tobias/.gradle/caches/modules-2/fi les-2.1/org.robolectric/robolectric/2.2/af902024b55e3b41732a7d9f41c32f90c065be2f/robolectric-2.2.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.codehau s.plexus/plexus-container-default/1.0-alpha-9-stable-1/94aea3010e250a334d9dab7f591114cd6c767458/plexus-container-default-1.0-alpha-9-stable-1.jar:/home/tobias/. gradle/caches/modules-2/files-2.1/backport-util-concurrent/backport-util-concurrent/3.1/682f7ac17fed79e92f8e87d8455192b63376347b/backport-util-concurrent-3.1.ja r:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-plugin-registry/2.2.1/72a24b7775649af78f3986b5aa7eb354b9674cfd/maven-plugin-registry-2. 2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-settings/2.2.1/2236ffe71fa5f78ce42b0f5fc22c54ed45f14294/maven-settings-2.2.1.jar: /home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-file/1.0-beta-6/6c53633505460caf49d2660de1e24744d915afb9/wagon-file-1.0-beta-6.jar: /home/tobias/.gradle/caches/modules-2/files-2.1/com.ximpleware/vtd-xml/2.11/ee5bcf62c1acf76434ee9f1c67a840bafef72a6d/vtd-xml-2.11.jar:/media/data/SDKs/android-s dk-linux_x86/extras/android/m2repository/com/android/support/support-v4/19.0.1/support-v4-19.0.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm /asm-commons/4.1/f8b86f4ee6e02082f63a658e00eb5506821253c6/asm-commons-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a 25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-analysis/4.1/73401033069e4714f57b60a eae02f97210aaa64e/asm-analysis-4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-artifact/2.2.1/23600f790d4dab2cb965419eaa982e3e84c 428f8/maven-artifact-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-profile/2.2.1/3950071587027e5086e9c395574a60650c432738/mav en-profile-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/com.google.android/support-v4/r7/24d0f6da34c3a2bfcf736ab42d51c91ac821ee22/support-v4-r7.jar :/home/tobias/.gradle/caches/modules-2/files-2.1/org.ow2.asm/asm-util/4.1/6344065cb0f94e2b930a95e6656e040ebc11df08/asm-util-4.1.jar:/home/tobias/.gradle/caches/ modules-2/files-2.1/org.apache.maven/maven-model/2.2.1/c0a1c17436ec3ff5a56207c031d82277b4250a29/maven-model-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/file s-2.1/org.easytesting/fest-util/1.2.5/c4a8d7305b23b8d043be12c979813b096df11f44/fest-util-1.2.5.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.an t/ant-launcher/1.8.0/8b53ba16fa62fb1034da8f1de200ddc407c8381/ant-launcher-1.8.0.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.codehaus.plexus/plexus-i nterpolation/1.11/ad9dddff6043194904ad1d2c00ff1d003c3915f7/plexus-interpolation-1.11.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.easytesting/fest-re flect/1.4.1/2b92d5275e92a49e16c7ce6bd7e46b9080db0530/fest-reflect-1.4.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven/maven-project/2.2.1 /8239e98c16f641d55a4ad0e0bab0aee3aff8933f/maven-project-2.2.1.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/org.apache.maven.wagon/wagon-provider-api/1.0- beta-6/3f952e0282ae77ae59851d96bb18015e520b6208/wagon-provider-api-1.0-beta-6.jar:/home/tobias/.gradle/caches/modules-2/files-2.1/nekohtml/xercesMinimal/1.9.6.2 /d1c5e063683a0e6f77cd5f051a9d4af48346fa6/xercesMinimal-1.9.6.2.jar ... The juni part is at the beginning now
  • 18. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Classpath goes into VM options Setup run configuration
  • 19. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Create a Gradle task Generate Robolectric classes
  • 20. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Add to JUnit configuration, Before launch Launch Robolectric configuration
  • 21. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 Big thanks to Ilkka Laukkanen Credits Further information: http://blog.futurice.com/android_unit_testing_in_ides_and_ci_environments
  • 22. Tobias Preuss – 26.03.2014 – GDG Android in Berlin – v.1.0.1 http://www.flickr.com/photos/dopey/123646856/ Questions