0
votes

I have a big TestNG suite that is invoked via 'test' task in Gradle. The suite runs just fine, but I'm having some difficulty with asking Gradle for the test suite information. Specifically, the lists of include and exclude groups.

My group configuration in my testng.xml looks something like this:

<groups>
  <run>
    <exclude name="notReady" />
  </run>
</groups>

My goal is to provide a means for the user to specify include/exclude groups at runtime using command line properties, and then add them to the appropriate lists in the testng config. The only catch is, I still need to respect the existing include/exclude config in the testng.xml file.

Here's a brief build.gradle example of what I'm trying to do in my task block (minus the command line parsing to keep the code simple):

test {
    useTestNG() {
        suites("src/test/resources/testng.xml")
        Set<String> excludeGroups = getExcludeGroups() // Returns an empty set
        excludeGroups.add("someOtherGroup")
        setExcludeGroups(excludeGroups)
    }
 }

I would expect excludeGroups to be ['notReady'], but instead I get back an empty set. The same thing happens with getIncludeGroups() as well. I suspect this is because suites() doesn't actually load and parse the XML file(s) when called, but I have no evidence to back that up.

I've been poring over the TestNGOptions docs, but I'm not sure if I'm doing something wrong or if that's just the expected behavior. Obviously I can work around the problem by defining my default include/exclude lists in build.gradle instead of the testng.xml, but that feels kind of clunky. If anyone could shine some light on this for me, it would be much appreciated.

Thanks,

Andy

1

1 Answers

0
votes

You can make groups configurable at runtime with the xml itself using beanshell.

Ref : http://testng.org/doc/documentation-main.html#beanshell