I have our project building using Gradle. I am now trying to add our tests to the build. I am not totally sure how this works, or what the actuall syntax to use would be.
Here is the build script for a test application I have been trying to get working. My tests are in the src/instrumentTest/java directory.
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
testPackage "com.example.myapplication.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
}
When I do a build I get the following error.
FAILURE: Build failed with an exception.
Where: Build file '/Users/kbrown/AndroidStudioProjects/MyApplicationProject/MyApplication/build.gradle' line: 22
What went wrong: A problem occurred evaluating project ':MyApplication'.
Could not find method testPackage() for arguments [com.example.myapplication.test] on ProductFlavorDsl_Decorated{name=main, minSdkVersion=8, targetSdkVersion=16, renderscriptTargetApi=-1, versionCode=-1, versionName=null, packageName=null, testPackageName=null, testInstrumentationRunner=null, signingConfig=null}.
Various attribute names have been changed in Gradle version 1.0
The 'testPackageName' is also replace by 'testApplicationId'
You can check more at Migrating Gradle Projects to version 1.0.0
The property name to set the package name of the test app is "testPackageName", not "testPackage".
Note that you don't have to provide this, it gets computed automatically based on the name of the tested app by default.
Same thing with the instrumentation runner class, setting it to the default runner has no effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With