假設我有一個junit
自定義類加載器,它從文本文件讀取測試數據並在運行時創建並運行測試。跑步者不使用測試課程。現在如何爲SureFire Maven插件指定JUnit自定義運行器?
我想與surefire
Maven插件運行。也就是說,我想指定跑步者作爲pom.xml
中surefire
插件「執行」的參數。
我可以這樣做嗎?
假設我有一個junit
自定義類加載器,它從文本文件讀取測試數據並在運行時創建並運行測試。跑步者不使用測試課程。現在如何爲SureFire Maven插件指定JUnit自定義運行器?
我想與surefire
Maven插件運行。也就是說,我想指定跑步者作爲pom.xml
中surefire
插件「執行」的參數。
我可以這樣做嗎?
編號據我所知,沒有辦法在maven-surefire插件中指定Runner
類。但是,您應該能夠創建一個測試課程並使用@RunWith(YourRunner.class)
來讓它與您的自定義跑步者一起運行。
我認爲這是因爲Runner
的預期用例在每個測試基礎,而不是項目級別。你可以有一個混合使用各種跑步者的項目,例如有些是基於Spring的,有些是併發的,有些是使用JUnit3運行的,有些使用JUnit4等。
根據您想要實現的目標,您可以使用自定義RunListener
來影響全局測試行爲。下面是如何使用Maven Surefire插件進行配置:http://maven.apache.org/plugins/maven-surefire-plugin/examples/junit.html#Using_custom_listeners_and_reporters
(我張貼了類似的問題,即同樣的反應:Globally setting a JUnit runner instead of @RunWith)
在我的項目我解決同樣的任務與插件exec-maven-plugin
我有自定義的Runner,它運行具有特殊參數的junit測試。我執行我的亞軍與Maven命令:MVN測試-Dparam1 =值-Dparam2 =數值-Dparam3 = VALUE3
在pom.xml中:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>com.example.domain.MyMainClass</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>