Android : Android Unit testing using gradle

on Monday, September 8, 2014


I want to do unit testing using gradle with out using any device or emulator, below is my code. Its not working, getting error like Could not find property 'output' on source set unit test can anybody suggest me how to resolve this.



buildscript {

repositories {
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:0.11+'
}
}

apply plugin: 'android'

android {
compileSdkVersion 19
buildToolsVersion '19.1'

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}

dependencies {
compile files('libs/android-support-v4.jar')
}

lintOptions {
abortOnError true
textReport true
textOutput 'stdout'
}

sourceSets {
unitTest {
java.srcDir file('src/test')
}
}

configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
dependencies {
unitTestCompile files("$project.buildDir/classes/release")
unitTestCompile 'junit:junit:4.8.2'
}
task unitTest(type:Test, dependsOn: assemble) {
description = "run unit tests"
testClassesDir = android.sourceSets.unitTest.output.classesDir
classpath = android.sourceSets.unitTest.runtimeClasspath
}

check.dependsOn unitTest


}

0 comments:

Post a Comment