Passing parameters to TestNG run


(federicolenzi) #1

I have some tests in TestNG and I use Gradle to run them. I have some properties in spring beans that I want to select at runtime. So, for select this different beans I want to pass string parameters to the useTestNG invocation. My build.gradle looks as follows:

apply plugin: 'java'
dependencies {
  compile fileTree(dir: 'lib', include: '*.jar')
}
test {
      useTestNG()
}

The parameters would be like “bean1”, “bean2”,… and in the Java code I’ll select what bean use.

ApplicationContext context = new FileSystemXmlApplicationContext("**/pathToXML.xml");
       Locators obj = (Locators) context.getBean("bean1");

If this isn’t a good way to solve this problem and a different approach is better I’ll be thankfully to know it


(Peter Niederwieser) #2

A simple solution is to use system properties:

test {
  systemProperty "testBean", "bean1"
}
...
context.getBean(System.getProperty("testBean"));