Alexiuscrow
Alexiuscrow

Reputation: 785

Gradle: What's wrong with assignment `excludeGroups` for TestNG?

There are project where I used TestNG & Gradle.
Test section from build.gradle file:

tasks.withType(Test) {
    useTestNG() {
        useDefaultListeners = true
        testLogging.showStandardStreams = true
    }
}

/*
    some code there
*/

task integTest(type: Test) {
    useTestNG() {
        excludeGroups = ['jt-someTest2', 'jt-someTest3'].toSet()
    }
}

For this case everithing works fine. But when I try some like this:

def allAvailableTestGroups = ['someTest1', 'someTest2', 'someTest3'].toSet()
def testGroup = project.hasProperty("testGroup") ? project.testGroup : 'all'


tasks.withType(Test) {
    useTestNG() {
        useDefaultListeners = true
        testLogging.showStandardStreams = true
    }
}

/*
    ...
    some code there
    ...
*/

task integTest(type: Test) {
    useTestNG() {
        excludeGroups = ( allAvailableTestGroups.collect { "jt-${it}" }.findAll { it != testGroup } ) as HashSet<String>
    }
}

I got such trouble:

org.gradle.internal.UncheckedException: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.GStringImpl
//...
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.runtime.GStringImpl
//...
Unexpected exception thrown.
org.gradle.internal.remote.internal.MessageIOException: Could not read message from '/127.0.0.1:58219'.
//...
Caused by: com.esotericsoftware.kryo.KryoException: java.io.IOException: ╙фрыхээ√щ їюёЄ яЁшэєфшЄхы№эю ЁрчюЁтры ёє∙хёЄтє■∙хх яюфъы■ўхэшх
//...
Caused by: java.io.IOException: ╙фрыхээ√щ їюёЄ яЁшэєфшЄхы№эю ЁрчюЁтры ёє∙хёЄтє■∙хх яюфъы■ўхэшх
//...
Unexpected exception thrown.
org.gradle.internal.remote.internal.MessageIOException: Could not write '/127.0.0.1:58219'.
//...
Caused by: java.io.IOException: ╙фрыхээ√щ їюёЄ яЁшэєфшЄхы№эю ЁрчюЁтры ёє∙хёЄтє■∙хх яюфъы■ўхэшх
//...
:integTest FAILED
FAILURE: Build failed with an exception.

What's wrong?

Upvotes: 2

Views: 850

Answers (1)

Renato
Renato

Reputation: 13690

Replace this line:

excludeGroups = ( allAvailableTestGroups.collect { "jt-${it}" }
    .findAll { it != testGroup } ) as HashSet<String>

With this:

excludeGroups = ( allAvailableTestGroups.collect { "jt-${it}".toString() }
    .findAll { it != testGroup } ) as Set

Looks like the Groovy compiler is missing the auto-translation of your GString "jt-$it" for some reason... calling toString() should fix that.

Upvotes: 1

Related Questions