【问题标题】:Maven Surefire: run a single unit testMaven Surefire:运行单个单元测试
【发布时间】:2011-02-28 23:24:19
【问题描述】:

我知道可以使用-Dtest=MyTest 运行特定的测试类。但是是否可以在该类运行特定的测试?

即如果MyTest 定义了testFoo()testBar(),有没有办法指定只运行testfoo()

我知道在 IDE 中执行此操作非常容易,但我有时需要在另一台服务器上的命令行上运行测试。

【问题讨论】:

    标签: java maven maven-surefire-plugin unit-testing


    【解决方案1】:

    来自Running a Single Test Using Maven Surefire Plugin

    使用 2.7.3 版,您只能在单个测试类中运行 n 个测试。

    注意:junit 4.x 和 TestNG 支持它。

    您必须使用以下语法

    mvn -Dtest=TestCircle#mytest test

    你也可以使用模式

    mvn -Dtest=TestCircle#test* test

    【讨论】:

      【解决方案2】:

      它将从 Surefire 2.8 开始提供,请参阅 SUREFIRE-577

      【讨论】:

        【解决方案3】:

        不要认为它可用。您可以通过传递一些系统属性并忽略基于属性值的测试执行来解决它。然而,它似乎并没有增加很大的附加值。还有提供附加功能的 TestNG。

        http://maven.apache.org/plugins/maven-surefire-plugin/examples/testng.html

        【讨论】:

          【解决方案4】:

          要一次执行一个测试,请运行 mvn test

          mvn -Dtest=MyUnitlTest test
          

          一次执行一个测试并从中执行一个特定的方法:

          mvn -Dtest=MyUnitTest#method test
          

          其中 MyUnitTest 是您的测试名称,#method 是您的方法名称。

          用万无一失的方式执行测试:

          mvn surefire:test
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-07-28
            • 1970-01-01
            • 1970-01-01
            • 2021-12-18
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多