Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.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/3/sql-server-2005/2.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
如何使用maven surefire插件运行所有测试文件并触发测试_Maven_Maven Plugin_Maven Surefire Plugin - Fatal编程技术网

如何使用maven surefire插件运行所有测试文件并触发测试

如何使用maven surefire插件运行所有测试文件并触发测试,maven,maven-plugin,maven-surefire-plugin,Maven,Maven Plugin,Maven Surefire Plugin,我正在maven建立一个项目 我有一些测试文件,我希望在编译或打包项目时执行它们 以下是我迄今为止所尝试的: xml如下所示 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.4</ver

我正在maven建立一个项目 我有一些测试文件,我希望在编译或打包项目时执行它们

以下是我迄今为止所尝试的:

  • xml如下所示

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12.4</version>
            <executions>
                <execution>
                    <id>test</id>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                        <includes>
                            <include>src/test/java/**/com.example.AllTests.java</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <skip>false</skip>
            </configuration>
        </plugin>
    
    
    org.apache.maven.plugins
    maven surefire插件
    2.12.4
    测试
    测试
    假的
    src/test/java/**/com.example.AllTests.java
    假的
    
  • 当我运行命令“mvn clean install test”时,surefire会运行,但它会跳过所有测试文件

  • 当我运行命令“mvn clean install-Dtest=com.example.AllTests.java-DfailIfNoTests=false”时,java文件成功运行

  • 在更大、更复杂的项目中,我不想运行多个命令。我只想运行一个命令,我想让maven运行测试文件,生成测试报告,然后继续运行应用程序

    有谁能帮我理解我是如何通过Maven实现这一点的


    提前感谢您的帮助。

    不要包含
    src/test/java/
    ,而是使用
    com/example/AllTests.java

    顺便说一句,对于surefire插件,不需要指定执行块,因为它已经作为构建生命周期的一部分被调用(除非您有一个罕见的设置)。这里的配置块就足够了。

    在第1点中,您有
    com.example.AllTests.java
    ,在第3点中它是单数
    com.example.AllTest.java
    哦,请忽略。。。让我编辑一下,汉克·罗布,我试试这个。