StackOverflowError using testng and specifying suites as a gstring with a project property reference

Title is a mouthful… Here’s an example that will help clarify:

testngSuite='unit'
  test {
   useTestNG() {
     //suites 'test/resources/conf/testng/testng-unit-test-suite.xml'
    suites "test/resources/conf/testng/testng-${testngSuite}-test-suite.xml"
  }
}

The idea behind this is that I want to support multiple testng suites – the default to run being unit tests. Optionally, on the command line someone can pass a -PtestngSuite=integration and a different set of tests will be run.

However, when I try to run ‘gradle build’, I get the following:

FAILURE: Build failed with an exception.
  * What went wrong:
A problem occurred evaluating project ':MyProject'.
Cause: java.lang.StackOverflowError (no error message)

The commented out suites line above works, however. Its only when I try to use preference my project property in the suite name.

In the meantime, to work around this, I’ve taken what is problem a more “gradle-like” approach in that I dynamically create tasks of type Test for each suite I can find in my test resource directory. That works great and I’ll probably stick with it.

But in my quest to become more knowledgable in Gradle and help to evangelize its use within my organization,

I’d be curious to know why my first approach failed.

Thanks.

Doug

I am also running into this problem when trying to set the excluded and included groups. Hard coded strings work fine.

Please provide the full output of ‘gradle -v’ and ‘gradle test -S’. Additionally, you can try to cast the GString to a String:

test {
   useTestNG {
     def suiteToRun = "test/resources/conf/testng/testng-${testngSuite}-test-suite.xml" as String
    println suiteToRun // check if output matches your expectation
    suites suiteToRun
  }
}