为什么 maven-surefire-plugin 会跳过带有日志消息 "because it has already been run for this configuration" 的测试?
Why maven-surefire-plugin skip tests with log message "because it has already been run for this configuration"?
我不明白为什么 maven-surefire-plugin 不 运行 jUnit4 测试。我的 pom 是(无法在此处添加,因为 "it looks post is mostly code"):http://pastebin.com/Jj3iJZpY
当我执行 mvn clean test
cmd window 时显示:
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] ------------------------------------------------------------------------
测试class是:
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 运行s 两次并且不想 运行 我的测试 class?如何 运行 测试我的情况?谢谢。
鉴于你 linked 的 pom(实际上应该包含在问题中,因为 link 将来可能会被破坏):
<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>
- Maven Surefire 插件运行两次,因为您配置了插件的额外执行,没有提供
id
元素,因此默认情况下它被称为 default
(maven-surefire-plugin:2.19:test (default)
) .此执行在 Surefire (maven-surefire-plugin:2.19:test (default-test)
) 的开箱即用 Maven 配置之后运行。因此,您有两次执行(default
和 default-test
)。删除 Surefire 插件配置中的 executions
部分,您将只有一次执行(default-test
)。
- 你的Surefire配置也有错别字,
<include>UtilTest.java</include>
配置指向UtilTest.java
class,而你的问题中它被命名为UtilsTest
(注意额外的 's').
- 如果测试class在
src/test/java
文件夹下,那么你不需要配置它的包含,因为它也已经遵循了Surefire的默认约定,"**/*Test.java"
。
- 您收到的消息 (
Skipping execution of surefire because it has already been run for this configuration
) 是因为 Surefire 插件的 configuration
元素在任何 executions
元素之外,这意味着适用于所有插件执行,甚至默认值 (default-test
).
因此,您可能可以从 pom 中删除整个 Surefire 插件部分,问题应该得到解决。
我不明白为什么 maven-surefire-plugin 不 运行 jUnit4 测试。我的 pom 是(无法在此处添加,因为 "it looks post is mostly code"):http://pastebin.com/Jj3iJZpY
当我执行 mvn clean test
cmd window 时显示:
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] ------------------------------------------------------------------------
测试class是:
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 运行s 两次并且不想 运行 我的测试 class?如何 运行 测试我的情况?谢谢。
鉴于你 linked 的 pom(实际上应该包含在问题中,因为 link 将来可能会被破坏):
<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>
- Maven Surefire 插件运行两次,因为您配置了插件的额外执行,没有提供
id
元素,因此默认情况下它被称为default
(maven-surefire-plugin:2.19:test (default)
) .此执行在 Surefire (maven-surefire-plugin:2.19:test (default-test)
) 的开箱即用 Maven 配置之后运行。因此,您有两次执行(default
和default-test
)。删除 Surefire 插件配置中的executions
部分,您将只有一次执行(default-test
)。 - 你的Surefire配置也有错别字,
<include>UtilTest.java</include>
配置指向UtilTest.java
class,而你的问题中它被命名为UtilsTest
(注意额外的 's'). - 如果测试class在
src/test/java
文件夹下,那么你不需要配置它的包含,因为它也已经遵循了Surefire的默认约定,"**/*Test.java"
。 - 您收到的消息 (
Skipping execution of surefire because it has already been run for this configuration
) 是因为 Surefire 插件的configuration
元素在任何executions
元素之外,这意味着适用于所有插件执行,甚至默认值 (default-test
).
因此,您可能可以从 pom 中删除整个 Surefire 插件部分,问题应该得到解决。