# Sharing test configs between different test tasks

**URL:** <https://discuss.gradle.org/t/sharing-test-configs-between-different-test-tasks/6772>\
**Category:** Old Forum Archive\
**Created:** [April 30, 2012, 3:51pm UTC](https://discuss.gradle.org/t/sharing-test-configs-between-different-test-tasks/6772 "2012-04-30T15:51:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil\_swenson](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@phil\_swenson](https://discuss.gradle.org/u/phil_swenson)\
**Post date:** [April 30, 2012, 3:51pm UTC](https://discuss.gradle.org/t/sharing-test-configs-between-different-test-tasks/6772/1 "2012-04-30T15:51:00Z")

</div>

I need to set some test configuration like a set of System Properties and JVM settings between my unit tests (plain test task) and my integration tests(tests that end in “IntegrationTest”) I tried this:

```gradle
test {
    systemProperty 'opt.terracotta', 'true'
    systemProperty 'opt.dev.home', '/Users/pswenson/dev/sag/optimize/trunk'
    systemProperty 'base.config.path', '/Users/pswenson/dev/sag/opt/trunk/modules/ae/src/main/resources/conf'
    //tuning the included/excluded tests
    include '**/*UnitTest.*'
    jvmArgs '-Xms128m', '-Xmx512m', '-XX:MaxPermSize=128m'
}
  task integrationTests(type: Test) {
    println ("tcsytemprop = ${System.getProperty('opt.terracotta')}")
    include '**/*IntegrationTest.*'
}

```

the tcsystemprop was output as null, so the test configuration isn’t shared just by declaring a task type “Test”

What should I do?

thanks!

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [April 30, 2012, 4:10pm UTC](https://discuss.gradle.org/t/sharing-test-configs-between-different-test-tasks/6772/2 "2012-04-30T16:10:00Z")

</div>

Hello phil, a system property defined in a test task is passed to the JVM that executes the tests. So when you do

```gradle
test{
    systemProperty 'myProp', 'somePath'
}

```

the systemProperty myProp is not available in other sections of your build script. Its only available in the context of your executed tests, as they use a JVM, that is configured with this systemProperty.

to share a configuration between your integrationTests task and your test task you can do:

```gradle
[test, integrationTests].each{
    systemProperty 'opt.terracotta', 'true'
    systemProperty 'opt.dev.home', '/Users/pswenson/dev/sag/optimize/trunk'
    systemProperty 'base.config.path', '/Users/pswenson/dev/sag/opt/trunk/modules/ae/src/main/resources/conf'
      }

```

If you want configure ALL your tasks of type ‘Test’ in your build you can do

```gradle
tasks.withType(Test){
    systemProperty 'opt.terracotta', 'true'
    systemProperty 'opt.dev.home', '/Users/pswenson/dev/sag/optimize/trunk'
    systemProperty 'base.config.path', '/Users/pswenson/dev/sag/opt/trunk/modules/ae/src/main/resources/conf'
    ...
}

```

regards, René

---

<div class="post-metadata">

**Author:** ![phil\_swenson](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@phil\_swenson](https://discuss.gradle.org/u/phil_swenson)\
**Post date:** [April 30, 2012, 4:36pm UTC](https://discuss.gradle.org/t/sharing-test-configs-between-different-test-tasks/6772/3 "2012-04-30T16:36:00Z")

</div>

I like your answer, but for some reason it’s not working:

` tasks.withType(Test) {`

systemProperty ‘opt.terracotta’, ‘true’

systemProperty ‘opt.dev.home’, ‘/Users/pswenson/dev/sag/optimize/trunk’

systemProperty ‘base.config.path’, ‘/Users/pswenson/dev/sag/opt/trunk/modules/ae/src/main/resources/conf’

jvmArgs ‘-Xms128m’, ‘-Xmx512m’, ‘-XX:MaxPermSize=128m’

beforeTest { descriptor -\>

logger.lifecycle("Running test: " + descriptor)

}

onOutput { descriptor, event -\>

logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message)

} }

test {

println(“testsytemprop = ${System.getProperty(‘opt.terracotta’)}”)

//tuning the included/excluded tests //

include ‘\*\*/_UnitTest._’

include ‘\*\*/_ProcessEventStageStorageUnitTest._’ } ``

I get output:

testsytemprop = null

---

<div class="post-metadata">

**Author:** ![phil\_swenson](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@phil\_swenson](https://discuss.gradle.org/u/phil_swenson)\
**Post date:** [April 30, 2012, 4:50pm UTC](https://discuss.gradle.org/t/sharing-test-configs-between-different-test-tasks/6772/4 "2012-04-30T16:50:00Z")

</div>

maybe it’s because the test configuration happens before the tasks.withType?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [April 30, 2012, 5:02pm UTC](https://discuss.gradle.org/t/sharing-test-configs-between-different-test-tasks/6772/5 "2012-04-30T17:02:00Z")

</div>

‘test.systemProperty()’ sets the system property in the test JVM, not in the Gradle JVM. Hence you can’t print it like that.

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [April 30, 2012, 5:03pm UTC](https://discuss.gradle.org/t/sharing-test-configs-between-different-test-tasks/6772/6 "2012-04-30T17:03:00Z")

</div>

what do you mean with “its not working”? Again, the line

```gradle
println("testsytemprop = ${System.getProperty('opt.terracotta')}")

```

in your the configuration of your task ‘test’ will allways print “testsystemprop = NULL”, as you try to load a SystemProperty on the java instance the gradle build uses.

All tasks of type ‘Test’ are executed in a seperate jvm instance. The systemProperty method of the Test task is used to pass system properties that you need in your tests to this newly created JVM instance. what you can do to check that your configuration is correctly, you can write a simple unit test that verifies, that your needed systemproperties are set correctly.

---

<div class="post-metadata">

**Author:** ![phil\_swenson](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@phil\_swenson](https://discuss.gradle.org/u/phil_swenson)\
**Post date:** [April 30, 2012, 5:08pm UTC](https://discuss.gradle.org/t/sharing-test-configs-between-different-test-tasks/6772/7 "2012-04-30T17:08:00Z")

</div>

This makes perfect sense, all good now.
