Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么maven surefire插件会使用日志消息“跳过测试”;因为它已经为此配置运行了;?_Java_Maven_Mule_Junit4_Maven Surefire Plugin - Fatal编程技术网

Java 为什么maven surefire插件会使用日志消息“跳过测试”;因为它已经为此配置运行了;?

Java 为什么maven surefire插件会使用日志消息“跳过测试”;因为它已经为此配置运行了;?,java,maven,mule,junit4,maven-surefire-plugin,Java,Maven,Mule,Junit4,Maven Surefire Plugin,我不明白为什么maven surefire插件不运行jUnit4测试。我的pom是(不能在这里添加它,因为“它看起来大部分是代码”): 当我执行mvn clean testcmd时,窗口显示: C:\Users\maya\git\services>mvn clean test [INFO] Scanning for projects... [INFO] [INFO] --------------------------------------------------------------

我不明白为什么maven surefire插件不运行jUnit4测试。我的pom是(不能在这里添加它,因为“它看起来大部分是代码”):

当我执行
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插件:2.19运行了两次,但不想运行我的测试类?如何在我的情况下运行测试?谢谢。

鉴于您链接的pom(实际上应该包括在问题中,因为链接可能会在将来断开):


org.apache.maven.plugins
maven surefire插件
2.19
测试
org.apache.maven.surefire
surefire-junit47
2.19
UtilTest.java
  • Maven Surefire插件运行两次,因为您配置了插件的附加执行,而不提供
    id
    元素,因此默认情况下称为
    default
    Maven Surefire插件:2.19:test(默认)
    )。此执行在Surefire的现成Maven配置之后运行(
    Maven Surefire插件:2.19:test(默认测试)
    )。因此,您有两个执行(
    default
    defaulttest
    )。删除Surefire插件配置上的
    执行
    部分,您将只执行一次(默认测试)
  • 您在Surefire配置中也有一个输入错误,
    UtilTest.java
    配置指向
    UtilTest.java
    类,而在您的问题中它被命名为
    UtilTest
    (请注意附加的“s”)
  • 如果测试类位于
    src/test/java
    文件夹下,则无需配置其包含,因为它也已遵循默认的Surefire约定,
    “***test.java”
  • 您收到的消息(
    跳过surefire的执行,因为它已经为此配置运行了
    )是因为surefire插件的
    配置
    元素在任何
    执行
    元素之外,这意味着应用于所有插件执行,即使是默认的(
    默认测试
因此,您可以从pom中删除整个Surefire插件部分,问题应该得到解决。

考虑到您链接的pom(实际上应该包括在问题中,因为将来链接可能会断开):


org.apache.maven.plugins
maven surefire插件
2.19
测试
org.apache.maven.surefire
surefire-junit47
2.19
UtilTest.java
  • Maven Surefire插件运行两次,因为您配置了插件的附加执行,而没有提供
    id
    元素,因此默认情况下它被称为
    default
    Maven Surefire插件:2.19:test(默认)
    )。此执行在Surefire的开箱即用Maven配置之后运行(
    maven-surefire-plugin:2.19:test(default test)
    )。因此,您有两次执行(
    default
    default test
    )。删除surefire-plugin配置中的
    executions
    部分,您将只执行一次(
    default test
  • 您在Surefire配置中也有一个输入错误,
    UtilTest.java
    配置指向
    UtilTest.java
    类,而在您的问题中它被命名为
    UtilTest
    (请注意附加的“s”)
  • 如果测试类位于
    src/test/java
    文件夹下,则无需配置其包含,因为它也已遵循默认的Surefire约定,
    “***test.java”
  • 您收到的消息(
    跳过surefire的执行,因为它已经为此配置运行了
    )是因为surefire插件的
    配置
    元素在任何
    执行
    元素之外,这意味着应用于所有插件执行,即使是默认的(
    默认测试

因此,您可以从pom中删除整个Surefire插件部分,问题应该得到解决。

谢谢。错误在
UtilTest.java
中。应该是UtilTest.java谢谢。错误在
UtilTest.java
中。应该是UtilTest.java
<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>