Hi,
to run different tests with different values for the SAME environment variable I suggest to split your tests in two seperate tasks like the following:

----------------------------------
task testWithProp1(type:Test){
    include '**/prop1/*'
    environment['TEST_PROP'] = 'PROP1'
    testClassesDir = sourceSets.test.classesDir
classpath = compileTestGroovy.outputs.files + configurations.testRuntime
}

task testWithProp2(type:Test){
    include '**/prop2/*'
    environment['TEST_PROP'] = 'PROP2'
    testClassesDir = sourceSets.test.classesDir
classpath = compileTestGroovy.outputs.files + configurations.testRuntime
}
----------------------------------

As you can see I set the environment value in the sample for 'TEST_PROP' to different values in both tasks. The include statement describes which of your tests are considered in each Task. The task "testWithProp1" includes all tests in the package prop1 and "testWithProp2" includes all tests in the package prop2.

regards,
René

Am 27.07.11 21:20, schrieb jean-philippe robichaud:
That was my next thing to try :)

BTW, would you happen to know if it is possible to set custom shell environment variables for the unit tests? My unit test requires the usage of a third party library that uses shell variables to find some shared libraries. I can't really set them before running the build because different unit tests will require different values for the same shell variable.

does the "test" section allows to set shell variables?

Thanks!

Jp

On Wed, Jul 27, 2011 at 3:15 PM, Rene Groeschke <[email protected] <mailto:[email protected]>> wrote:

    Hi jean,
    if you use groovy for your tests, you may replace


    apply plugin:'java-base'
    apply plugin:'groovy'

    with apply :'groovy-base'

    regards,
    René

    Am 27.07.11 21:03, schrieb jean-philippe robichaud:
    Thanks René, that's working beautifully.

    For the records, here is my build.gradle file.  I've actually put
    the "test" feature into a separate project (instead of embedding
    it into each subprojects).  I've also enabled the "groovy" plugin
    since it is so much easier to write my test in groovy...

    build.gradle:

    apply plugin:'java-base'
    apply plugin:'groovy'

    repositories{
       mavenCentral()
    }
    configurations {
       testCompile { extendsFrom compile }
       testRuntime { extendsFrom testCompile, runtime }
    }

    sourceSets {
       test {
           compileClasspath = configurations.testCompile
           runtimeClasspath = classes + configurations.testRuntime
           groovy {
               srcDir =  "src/test/groovy"
           }
       }
    }

    dependencies{
       groovy group: 'org.codehaus.groovy', name: 'groovy', version:
    '1.8.0'
       testCompile "junit:junit:4.8.2"
    }

    test {
        systemProperties 'basedir': project.projectDir;
    }


    Again, thanks!

    Jp


    On Tue, Jul 19, 2011 at 4:55 PM, Rene Groeschke
    <[email protected] <mailto:[email protected]>> wrote:

        Hi,
        the easiest way to add junit infrastructure to your project
        is to use the java-base plugin instead of the java plugin.
        Applying the base java plugin, you have to define the
        sourcesets and test task on your own. The following snippet
        adds a test task and the according compile tasks for a
        sourceset that contains your tests only. no productive java
        sourceset is defined:
        ----------------------
        apply plugin:'java-base'

        repositories{
           mavenCentral()
        }
        configurations {
           testCompile { extendsFrom compile }
           testRuntime { extendsFrom testCompile, runtime }
        }

        sourceSets {
           test {
               compileClasspath = configurations.testCompile
               runtimeClasspath = classes + configurations.testRuntime
           }
        }

        dependencies{
           testCompile "junit:junit:4.8.2"
        }

        task test(type:Test){
           testClassesDir = sourceSets.test.classesDir
           classpath = compileTestJava.outputs.files +
        configurations.testRuntime
        }
        ----------------------

        now executing gradle test should do the trick.

        regards,
        René

        Am 19.07.11 20:54, schrieb jean-philippe robichaud:

            Hi everyone.

            I've relatively new to Gradle and I'm using it
            successfully for my non-java project.  We are building
            "grammars" using various custom perl & groovy scripts and
            I manage to rapidly wrap a build system thanks to Gradle
            (very good tool btw!). We're using the 'multi-project'
            approach where each artifact is build by one project.
            Overall, it's pretty clean.

            Now I would like to use junit tests to perform various
            validation and verification steps on the many grammars
            produced.  Is there a way I could 'recycle' the 'test'
            infrastructure to be able to produce junit tests and
            profit for the built-in reports?  From what I understood,
            that's tied to the 'java' plugin (which I'm not using
            because I'm not compiling java code).

            Thanks for your help!

            Jp



-- -----------------------
        regards René

        rene groeschke
        http://www.breskeby.com
        @breskeby


        ---------------------------------------------------------------------
        To unsubscribe from this list, please visit:

        http://xircles.codehaus.org/manage_email





-- -----------------------
    regards René

    rene groeschke
    http://www.breskeby.com
    @breskeby




--
-----------------------
regards René

rene groeschke
http://www.breskeby.com
@breskeby

Reply via email to