Question

I want to make test of some clases in my project.

I'm project is all android, but the new clases are pure Java (I'm trying to make a little sdk for the app)

But I don't know how to configure correctly

Gradle file:

apply plugin: 'android'

android {
    compileSdkVersion "Google Inc.:Google APIs:19"
    buildToolsVersion "19.0.1"

    lintOptions{
        checkReleaseBuilds false
    }

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 28
        versionName "4.0.5"
    }

    signingConfigs {
        debug {
                        ..........
        }

        release {
                        ..........
        }

    }

    buildTypes {

        debug{
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            debuggable true
            buildConfigField "boolean", "LOG_ENABLED", "true"
            signingConfig signingConfigs.debug
        }

        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            debuggable false
            buildConfigField "boolean", "LOG_ENABLED", "false"
            signingConfig signingConfigs.release
        }
    }

    productFlavors{
        develFlavor{

        }

        testFlavor{
            ..........
        }

        trainingFlavor{
            ..........
        }

        preFlavor{
            ..........
        }

        proFlavor{
            .........
        }
    }

}

if (project.hasProperty('storePassword')) {
    android.signingConfigs.release.storePassword = storePassword
}

if (project.hasProperty('keyAlias')) {
    android.signingConfigs.release.keyAlias = keyAlias
}

if (project.hasProperty('keyPassword')) {
    android.signingConfigs.release.keyPassword = keyPassword
}



repositories {
    mavenCentral()
}

sourceSets {
    test {
        java.srcDir file(''src/main/java/es/tempos/gas/sdk/test'')
    }
}

dependencies {
    unitTestCompile 'junit:junit:4.11'
    compile 'com.google.code.gson:gson:1.7.1'
    compile 'com.android.support:appcompat-v7:+'
    compile files('libs/libGoogleAnalyticsServices.jar')
    compile files('libs/sbc_mapslib.jar')
    compile files('libs/t21c2dm-lib-v1.0.jar')
}

I want to put the test cases in the folfer Test>SDK

Estructure of the app:

+SmartPhoneGreatApp
----.idea
----app
    -----build
    -----libs
    -----src
         -----develFlavor
         -----main
              ----sdk
         -----preFlavor
         ----- .........
         ........
    -----test
         ------sdk

and the testing class(for the moment do nothing)

package es.tempos21.gas.sdk.test;

import org.junit.Test;


public class AuthenticateTest {


    @Test
    public void testAuthenticate() throws Exception {

    }
}

And the error I'm getting:

Gradle 'SmartPhoneGreatApp' project refresh failed:
         Could not find property 'unitTest' on SourceSet container.
         Gradle settings
Was it helpful?

Solution

In the Android plugin, sourceSets are configured differently from how the Java plugin does it, so you should read the docs at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Sourcesets-and-Dependencies

For testing you'll want to do something like this:

android {
    sourceSets {
        androidTest.setRoot('tests')
    }
}

A shortcut would be to do this instead:

android.sourceSets.androidTest.setRoot('tests')

Note that you're supplying a new top-level directory for where the tests go (and the Java classes will be in a directory structure underneath that corresponds to their package path); in your example you're trying to point it at a package already inside src/main/java/path/to/package, which isn't going to work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top