![](/img/trans.png)
[英]How to make maven-surefire-plugin work with TestNG in Eclipse
[英]Maven-surefire-plugin with TestNg : how to specify the directory where test suites xml files are stored?
我目前正在开发Maven支持的项目。 我选择了TestNg来实现我的单一测试。 为了在每个Maven构建中运行我的单一测试,我已经将maven-surefire-plugin添加到我的pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<!-- Configuring the test suites to execute -->
<suiteXmlFiles>
<suiteXmlFile>testsuite-persistence-layer.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
此外,我想指定使用TestNg的TestSuiteXmlFile执行的测试。 例如,在我的pom.xml中,我配置了surefire插件,以便它将执行名为“testsuite-persistence-layer.xml”的xml文件中定义的测试。
问题是默认情况下,surefire插件似乎在我的项目的根目录中寻找这个xml文件。 如何指定surefire插件应该在哪个目录中查找TestSuite xml文件?
根据TestNg文档,这可以通过“maven.testng.suitexml.dir”属性指定,但Surefire插件似乎没有考虑到它。
我不确定我是否理解你的问题。 您可以轻松指定xml文件的确切位置,包括相对路径和完全限定路径。
<suiteXmlFile>c:/some/dir/testsuite-persistence-layer.xml</suiteXmlFile>
要么
<suiteXmlFile>src/test/java/com/something/project/testsuite-persistence-layer.xml</suiteXmlFile>
但这太容易了,所以我猜你正在寻找一种方法来参数化xmls所在的目录。 我想到的快速解决方案就是
<suiteXmlFile>${xmlPath}/testSuite.xml</suiteXmlFile>
现在你可以跑了
mvn test -DxmlPath=c:/some/path
当然xmlPath只是一个虚构的名称,你可以使用你想要的任何其他变量名。
如果您不想从命令行将路径作为参数传递,则可以在POM的属性部分中指定xmlPath变量的值。 属性是位于<project>分支下的主要部分之一。
<project ... >
...
<properties>
<xmlPath>c:/some/path</xmlPath>
</properties>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${xmlPath}/testSuite.xml</suiteXmlFile>
</suiteXmlFiles>
...
</configuration>
</plugin>
...
</plugins>
...
</build>
...
</project>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.