[英]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.