Hi!
I came up with a way to run unit tests on the local machine, without
running the emulator.
It relies on mocking (Mockito) to deal with the classes from the
Android-api.
Initially I used Robolectric, but I ran into some issues with variant
support.
Also, I suspect the normal androidTests doesn't run when using Robolectric
(either vanilla or Robolectric runs).
Some parts are hackish and I would like your suggestions on how to make it
cleaner!
Especially I'm interested in how to make the test folders register with
Android Studio.
Here is my code, for plugin version 0.11, tested with Gradle 1.12.
I execute the tests by 'gradle unitTest' and the output is put into
build/reports/tests and build/test-results like normally in Gradle.
sourceSets {
test {
java.srcDir file('src/test/java')
resources.srcDir file('src/test/resources')
// Add test-dependencies to classpath
compileClasspath += configurations.testCompile
// Add our classes to classpath
compileClasspath +=
files("${buildDir}/intermediates/classes/plain/debug")
runtimeClasspath = output + compileClasspath
}
}
task unitTest(type: Test) {
testClassesDir = sourceSets.test.output.classesDir
classpath = sourceSets.test.runtimeClasspath
}
check.dependsOn unitTest
android.libraryVariants.all {
if (it.name.equals("plainDebug")) {
testClasses.dependsOn(it.javaCompile)
}
}
dependencies {
// compile time dependencies are left out in this example
testCompile('junit:junit:4.11')
testCompile 'com.squareup:fest-android:1.0.8'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile
files(plugins.findPlugin('android-library').getBootClasspath()) // android
jar
}
--
You received this message because you are subscribed to the Google Groups
"adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.