Maven不使用<skiptests> true </skiptests>跳过测试

时间:2019-03-22 15:39:05

标签: eclipse maven junit

如果我在命令行上运行maven:

mvn clean install -DskipTests

这实际上是有效的,它会跳过测试,但是如果我在eclipse中这样做,它仍然会始终运行测试

<plugins>
       <!-- Maven Assembly Plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <excludes>
                            <exclude>**/UTest*.java</exclude>
                        </excludes>
                        <maven.test.skip>true</maven.test.skip>
                        <skipTests>true</skipTests>
                        <!-- get all project dependencies -->
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>                                    <mainClass>com.example.MyMainClass/mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>
            </executions>
        </plugin>

所以我尝试了三种不同的方法,所有这些都显示在上面:

1) <skipTests>true</skipTests>
2) <maven.test.skip>true</maven.test.skip>
3) <excludes>...</excludes>

在eclipse之内,它将始终运行测试

1 个答案:

答案 0 :(得分:1)

assembly插件无法运行测试。 Maven贯穿生命周期各个阶段。 install阶段将触发(并非穷举)编译器插件,surefire,故障安全,组装。

更多信息,What are Maven goals and phases and what is their difference?

surefire插件可以处理单元测试的运行,要完全跳过测试,您可以在插件配置中添加以下内容

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>

故障保护是集成测试运行器。