【问题标题】:Why no test is run when execute mvn test -P{profile Id}为什么执行 mvn test -P{profile Id} 时没有运行测试
【发布时间】:2021-03-04 16:57:49
【问题描述】:

我在 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 output

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

【问题讨论】:

  • 您正在指定一个套件 XML 文件。因此它将运行除此插件的默认调用之外的其他测试。在 target 目录中指定 XML 文件似乎不正确。可能没有!

标签: java selenium maven testng


【解决方案1】:

查看输出文件后,我注意到每个配置文件都在运行不同版本的 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>

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

【讨论】:

  • 我试过mvn test -P Test123,结果还是一样。没有运行测试。
猜你喜欢
  • 2019-02-19
  • 2012-10-13
  • 2018-07-16
  • 1970-01-01
  • 2021-08-14
  • 1970-01-01
  • 2015-12-21
  • 2020-01-12
  • 2019-02-28
相关资源
最近更新 更多