Julian A.
Julian A.

Reputation: 11470

Gradle android test plugin doesn't find tests

I'm trying to set up unit testing using Android Studio, Gradle and Jake Wharton's gradle-android-test-plugin.

But when I run $ ./gradlew test, test results get generated in build/test-report, but they show that no tests were found.

Do I need to configure the location of the test source?

The project is structured like so

MyProject
    build
    libs
    src        
        main
            java
                com
                    myproject
                        MainActivity.java
            res
        test
            java
               com
                   myproject
                      DemoTest.java
                      RobolectricGradleTestRunner.java

When I run $ ./gradlew test --info to get more info, I notice the following in the output. Could this be a clue to why the tests aren't being found?

:MyProject:testDebug 
file or directory '[...]/MyProject/build/test-classes/debug', not found 
Skipping task ':MyProject:testDebug' as it is up-to-date (took 0.508 secs).

Here's the build.gradle:

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
        classpath 'com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
    }
}

apply plugin: 'android'
apply plugin: 'android-test'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 19
    }
}

dependencies {
    compile fileTree(dir: 'libs/main', include: '*.jar')
    testCompile 'junit:junit:4.10'
    testCompile 'org.robolectric:robolectric:2.1.+'
    testCompile 'com.squareup:fest-android:1.0.+'
}

Upvotes: 1

Views: 2519

Answers (1)

UXkQEZ7
UXkQEZ7

Reputation: 1184

add

sourceSets {
    instrumentTest.setRoot('src/test')
}

in android { ... }

Upvotes: 3

Related Questions