Java 如何避免在使用mvn clean安装时在maven中不使用skipTests而运行测试用例

Java 如何避免在使用mvn clean安装时在maven中不使用skipTests而运行测试用例,java,spring-boot,maven,Java,Spring Boot,Maven,我已经编写了测试用例,但当我运行mvn clean install测试用例时,它正在激活。当我使用特定配置文件时,我的用例不需要在运行mvn clean install时运行测试用例,然后只激活测试用例。您可以在pom.xml中配置surefire插件以包括/排除基于名称进行测试,并对要运行这些测试的配置文件使用不同的配置。 比如: <profiles> <profile> <id>without-tests</id>

我已经编写了测试用例,但当我运行mvn clean install测试用例时,它正在激活。当我使用特定配置文件时,我的用例不需要在运行mvn clean install时运行测试用例,然后只激活测试用例。

您可以在pom.xml中配置surefire插件以包括/排除基于名称进行测试,并对要运行这些测试的配置文件使用不同的配置。
比如:

<profiles>
    <profile>
        <id>without-tests</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <excludes>
                            <exclude>**/someTests.java</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>without-other-tests</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <excludes>
                            <exclude>**/otherTests.java</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

未经测试
org.apache.maven.plugins

用后缀命名您不想运行的测试,使您能够对它们进行分组

e、 g.有时我们使用
…FunctionalTest
来标记功能测试。然后,作为标准构建的一部分,在运行单元测试时可以对这些测试进行分组/包括/排除

有关更多信息,请参阅本文