java - TestNG - running specific tests programically -
i trying create testng.xml programmatically. use below java code
public static createtestsuit(string testclass){ xmlsuite suite = new xmlsuite(); suite.setname("my suite"); xmltest test = new xmltest(suite); test.setname("my test"); list<xmlclass> classes = new arraylist<xmlclass>(); classes.add(new xmlclass(testclass)); test.setxmlclasses(classes) ; list<xmlsuite> suites = new arraylist<xmlsuite>(); suites.add(suite); testng tng = new testng(); tng.setxmlsuites(suites); tng.run(); }
the class 'testclass' contains several test methods. don't want run these methods. how can specify test method names want run in above code, above method should like
public static createtestsuit(string testclass, list<string> testcasesid){ //code }
note: test methods in form
@test(testname="testcaseid") public void test1(){ }
use xmlinclude
include test methods want.
xmlclass xmlclass = new xmlclass(""); list<xmlinclude> includemethods = new arraylist<>(); includemethods.add(new xmlinclude("test1")); xmlclass.setincludemethods(includemethods);
if include methods list not defined or defined empty testng run tests in class. otherwise it'll run included tests method names.
Comments
Post a Comment