4

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}.

3 Answers 3

14

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

Sign up to request clarification or add additional context in comments.

Comments

5

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.

3 Comments

Thanks. The funny thing is testPackage is pulled directly from the documentation. So while it is all computed automatically how do I run the tests? When I do a build I get no output from the tests.
I just fixed the docs, there was indeed one reference to "testPackage". What do you mean when you build you don't get output from the test. Are you just running "gradlew build"? If you want to run tests on device you'll need to run "gradlew connectedCheck"
ok thanks. I have been reading so much documentation the past few days, my head was starting to hurt and everything was blurring together.
4

If you have some problem now, see this issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.