[英]Why maven-surefire-plugin skip tests with log message “because it has already been run for this configuration”?
我不明白為什么maven-surefire-plugin不運行jUnit4測試。 我的pom是(無法在此處添加它,因為“它看起來大部分是代碼”): http : //pastebin.com/Jj3iJZpY
當我執行mvn clean test
cmd窗口時顯示:
C:\Users\maya\git\services>mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building services 1.0.18
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ services ---
[INFO] Deleting C:\Users\maya\git\services\target
[INFO]
[INFO] --- maven-mule-plugin:1.9:attach-test-resources (default-attach-test-resources) @ services ---
[INFO] attaching test resource C:\Users\maya\git\services\src\main\app
[INFO]
[INFO] --- build-helper-maven-plugin:1.7:add-resource (add-resource) @ services ---
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ services ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] Copying 3 resources
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-mule-plugin:1.9:filter-resources (default-filter-resources) @ services ---
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ services ---
[INFO] Compiling 60 source files to C:\Users\maya\git\services\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ services ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ services ---
[INFO] Compiling 1 source file to C:\Users\maya\git\services\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.19:test (default-test) @ services ---
[INFO]
[INFO] --- maven-surefire-plugin:2.19:test (default) @ services ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.554 s
[INFO] Finished at: 2015-12-11T15:48:05+03:00
[INFO] Final Memory: 48M/312M
[INFO] ------------------------------------------------------------------------
測試類是:
package com.comp.utils.UtilsTest;
import static org.junit.Assert.assertTrue;
import org.apache.log4j.Logger;
import org.junit.Test;
public class UtilsTest {
private static final Logger LOG = Logger.getLogger(UtilsTest.class.getName());
@Test
public void testHasPersonSameProd() {
boolean hasSameProduct = false;
assertTrue("Should be True", hasSameProduct);
}
}
為什么maven-surefire-plugin:2.19運行兩次並且不想運行我的測試類? 我該如何進行測試? 謝謝。
給定您鏈接的pom(實際上應該將其包含在問題中,因為將來鏈接可能會斷開):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.19</version>
</dependency>
</dependencies>
<configuration>
<includes>
<include>UtilTest.java</include>
</includes>
</configuration>
</plugin>
id
元素,因此默認情況下將其稱為default
( maven-surefire-plugin:2.19:test (default)
)。 此執行在Surefire的現成Maven配置之后運行( maven-surefire-plugin:2.19:test (default-test)
)。 因此,因此,您有兩個執行( default
和default-test
)。 刪除Surefire插件配置上的executions
部分,您將只能執行一次( default-test
)。 <include>UtilTest.java</include>
配置指向UtilTest.java
類,而在您的問題中它被命名為UtilsTest
(請注意其他“ s”)。 src/test/java
文件夾下,則無需配置其包含,因為它也已經遵循Surefire的默認約定"**/*Test.java"
。 Skipping execution of surefire because it has already been run for this configuration
的消息( Skipping execution of surefire because it has already been run for this configuration
)是因為您的Surefire插件的configuration
元素在任何executions
元素之外,這意味着將應用於所有插件執行,甚至是默認的( default-test
)。 因此,您可以從pom中刪除整個Surefire插件部分,並且該問題應已解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.