如何配置pom.xml文件,這樣我可以在不使用的testng.xml文件運行我的測試腳本?如你所知,我們可以動態地創建使用XmlSuite,XmlClass,Xmltest的和TestNG對象的testng.xml文件。如何執行TestNG的和Maven沒有的testng.xml文件
public class ScriptTest010 {
public static void main(String[] args) {
List<XmlSuite> suites = new ArrayList<XmlSuite>();
XmlSuite suite = new XmlSuite();
suites.add(suite);
List<XmlClass> classes = new ArrayList<XmlClass>();
XmlClass clz = new XmlClass();
clz.setClass(SampleTest.class);
classes.add(clz);
XmlTest test = new XmlTest(suite);
test.setClasses(classes);
Map<String, String> params = new HashMap<String, String>();
params.put("username", "mquraishi");
params.put("password", "nopassword1$");
params.put("search", "eat pray love");
test.setParameters(params);
XmlInclude testLogin = new XmlInclude("testLogin");
List<XmlInclude> includes = new ArrayList<>();
includes.add(testLogin);
clz.setIncludedMethods(includes);
TestNG testNg = new TestNG();
testNg.setXmlSuites(suites);
testNg.run();
}
}
你需要遵循的唯一的事情是:命名慣例例如'ScriptTest.java'並添加TestNG的作爲依賴於您的項目.... – khmarbaise