I have 3 java test classes. 1. ListenerTest1.java 2. ListenerTest2.java 3. ListenerMain.java
Above two testfixture classes i.e ListenerTest1.java and ListenerTest2.java have test methods . Also , having build.gradle file as :-
task automationTests(type: Test) {
systemProperty 'serviceType', System.properties['serviceType']
useTestNG {
useDefaultListeners = true
suiteXmlBuilder().suite(name: 'Testing case') {
test(name: 'ServiceUITests', annotations: 'JDK', verbose: '1') {
classes([:]) {
'class'(name: 'company.platform.ListenerMain')
}
}
}
}
}
So, while running my hudson job , it calls the task i.e automationTests and runs my ListenerMain class. I need to add if/else condition in the ListenerMain class file which will differentiate to run the either of the above two classes mentioned i.e ListenerTest1.java or ListenerTest2.java on the basis of System.property added in hudson job.
E.g
@Listeners(value = {PreconditionListener.class})
public class ListenerMain {
private static String serviceTypeUseParameter ;
private static Logger logger = LogManager.getLogger(ListenerMain .class.getName());
@BeforeClass
//TestNg Annotation
public void setup()
{
//############# Hudson job parameter is serviceType ##########
serviceTypeUseParameter = System.getProperty("serviceType");
if (serviceTypeUseParameter.equals("ListenerTest1Method")){
// Run ListenerTest1 class
}
else{
// Run ListenerTest2 class
}
}
}
What code need to be added for loading the class as per if/else condition ? I can add main method in ListenerMain class if required.