首页 > 解决方案 > 为什么执行 mvn test -P{profile Id} 时没有运行测试

问题描述

我在 pom.xml 中定义了我的配置文件,如下所示:

<profiles>
    <profile>
        <id>Test123</id>
        <build>
            <pluginManagement>
                <plugins>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.8.1</version>
                        <configuration>
                            <!-- put your configurations here -->
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M5</version>
                        <configuration>
                            <suiteXmlFiles>
                                <suiteXmlFile>src/target/testdemo.xml</suiteXmlFile>
                            </suiteXmlFiles>
                        </configuration>
                    </plugin>

                </plugins>
            </pluginManagement>
        </build>
    </profile>
</profiles>

我们我运行了一个命令mvn test -PTest123,没有运行测试,如下所示: cmd 输出

但是,我们使用命令mvn test运行,它已经运行了如下所示的测试: cmd 输出

标签: javaseleniummaventestng

解决方案


查看输出文件后,我注意到每个配置文件都在运行不同版本的 maven-compiler-plugin 和 maven-surefire-plugin。这个项目是否依赖于父 pom.xml?否则将插件上的版本更改为:

        <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <!-- put your configurations here -->
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.12.4</version>
                    <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>src/target/testdemo.xml</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>

如果版本控制不重要,应该解决问题。


推荐阅读