【问题标题】:Choosing test category on command line在命令行上选择测试类别
【发布时间】:2016-11-11 19:40:19
【问题描述】:

我正在使用 JUnit 的类别将我的测试分成不同的类别,并使用 maven 编译和运行我的测试(万无一失和故障安全)。

问题是,如何选择从命令行执行的测试类别?

类似:mvn clean install -DloadTests.

我的故障保护插件:

                 <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-failsafe-plugin</artifactId>
               <version>${failsafe.plugin.version}</version>
               <configuration>
                <!--Exclude load tests by default-->
                 <excludedGroups>com.test.lib.categories.LoadTestCategory</excludedGroups>
               </configuration>
             </plugin>

【问题讨论】:

    标签: java maven testing junit


    【解决方案1】:

    您可以使用配置文件并在其中指定插件配置。

    <profiles>
        <profile>
            <id>noLoadTests</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${failsafe.plugin.version}</version>
                        <configuration>
                            <!--Exclude load tests by default-->
                            <excludedGroups>com.test.lib.categories.LoadTestCategory</excludedGroups>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    

    然后运行maven

    mvn test -PnoLoadTests
    

    如果您只需要排除/包含一个特定类别,您还可以在配置文件中定义一个属性并在 .更多信息可以看here

    编辑:在这种情况下,提供的另一个答案是更好的答案,但配置文件允许各种高级配置。

    【讨论】:

      【解决方案2】:

      根据the documentation,用户属性称为groups。因此这应该有效:

      mvn clean install -Dgroups=com.test.lib.categories.LoadTestCategory

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-25
        • 2021-11-27
        • 1970-01-01
        • 1970-01-01
        • 2014-12-22
        相关资源
        最近更新 更多