我使用代碼生成器 JAVA 程式將單元測驗源生成到target\generated-test-sources我成功編譯到的單元測驗源中,target\test-classes但它們被 maven 構建忽略。我用mvn clean test.
在我的 pom.xml 檔案中,我有一個com.mypackage.TestCaseGenerator系結到generate-test-sources階段的主類的執行目標。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>myexec</id>
<phase>generate-test-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<classpathScope>test</classpathScope>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.mypackage.TestCaseGenerator</argument>
<argument>target/generated-test-sources/somedir</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-test-sources/somedir</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
right-click -> run as JUnit Test當我使用on從 Eclipse 運行測驗用例時target/generated-test-sources/somedir,測驗會正確執行。
我是否缺少一些 Maven 配置?
uj5u.com熱心網友回復:
如果您生成的測驗的類/檔案名與 Maven Surefire 插件的默認值不匹配,您將必須配置它以包含另一種模式的測驗。
有關測驗的包含和排除,請參閱官方插件檔案:
默認情況下,Surefire 插件將自動包含具有以下通配符模式的所有測驗類:
"**/Test*.java"- 包括其所有子目錄和所有以“Test”開頭的 Java 檔案名。"**/*Test.java"- 包括其所有子目錄和所有以“Test”結尾的 Java 檔案名。"**/*Tests.java"- 包括其所有子目錄和所有以“Tests”結尾的 Java 檔案名。"**/*TestCase.java"- 包括其所有子目錄和所有以“TestCase”結尾的 Java 檔案名。
<includes>您可以使用插件配置的或<excludes>部分配置不同的模式。您將在上面鏈接的檔案頁面上找到有關如何執行此操作的很好示例。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/534377.html
標籤:爪哇行家
