[英]How to run dynamic testng.xml using maven mvn test command line?
I created a test runner that create a dynamic testng xml so I can run tests suits with parameters.我创建了一个创建动态 testng xml 的测试运行器,因此我可以运行带有参数的测试套装。 All @Test methods are in the relevant class (for example LoginTest.class).
所有@Test 方法都在相关的 class 中(例如 LoginTest.class)。 It run perfectly from the IDE but with Maven (mvn test) it just print BUILD SUCCESS but not run any test…
它从 IDE 完美运行,但使用 Maven(mvn 测试)它只打印 BUILD SUCCESS 但不运行任何测试......
maven-surefire-plugin in POM.xml: POM.xml 中的 maven-surefire-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<environmentVariables>
<suite>LoginTest</suite>
</environmentVariables>
<includes>
<include>src/test/java/runner/TestRunner.java</include>
</includes>
</configuration>
</plugin>
My TestRunner class:我的TestRunner class:
public class TestRunner {
public static void main(String[] args) {
XmlSuite suite = new XmlSuite();
suite.setName("D-Web");
suite.setThreadCount(1);
suite.setVerbose(1);
//suite.setParallel("tests");
suite.addListener("com.app.listeners.ReportListeners");
XmlTest test = new XmlTest(suite);
test.setName("Tests");
test.setPreserveOrder(true);
XmlClass testClass = getTestClass();
List<XmlClass> classes = new ArrayList<>();
classes.add(testClass);
test.setXmlClasses(classes);
TestNG testng = new TestNG();
List<XmlSuite> suites = new ArrayList<>();
suites.add(suite);
testng.setXmlSuites(suites);
testng.run();
}
public static XmlClass getTestClass() {
switch (System.getenv("suite")) {
case "LoginTest":
default:
return new XmlClass(LoginTest.class);
case "PurchaseFunnelTest":
return new XmlClass(PurchaseFunnelTest.class);
case "QuestionnaireTests":
return new XmlClass(QuestionnaireTest.class);
}
}
}
My LoginTest class:我的登录测试 class:
public class LoginTest {
@Test
public void test1() {
System.out.println("Test 1 is running...");
}
}
I have just tried your project and it is running from mvn test command.我刚刚尝试了您的项目,它是从mvn test命令运行的。 From where you are running your maven command?
从哪里运行 maven 命令? Just go to your project directory where pom.xml is present and run your command, it should work fine.
只需将 go 放到 pom.xml 所在的项目目录并运行您的命令,它应该可以正常工作。 Also I have added your LoginTest class in runner package along with your TestRunner class and it is working fine with IDE as well as command line.
Also I have added your LoginTest class in runner package along with your TestRunner class and it is working fine with IDE as well as command line.
Please test again and let me know.请再次测试并告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.