【问题标题】:How can I run a test suite using gradle from the command line如何从命令行使用 gradle 运行测试套件
【发布时间】:2015-08-27 16:23:07
【问题描述】:

我正在尝试使用 gradle 通过以下命令运行测试,但它不起作用

gradle cleanTest test --tests my.package.TestSuite

我的测试套件如下所示

@RunWith(Suite.class)
@Suite.SuiteClasses({
    ATests.class,
    BTests.class,
    CTests.class
})
public class MySuite {
  /* placeholder, use this to contain all integration tests in one spot * */
}

尝试运行以下命令是可行的,但更糟糕的是,它会运行每个测试两次。单独一次,然后在同一个命名空间中的测试套件下再次

gradle clean test --tests my.package.*

我可以放弃测试套件并以这种方式进行,但我想更好地了解这里发生了什么以及为什么我不能告诉它直接运行测试套件。

【问题讨论】:

  • 不确定是否可以从命令行执行。可能您需要为此定义一个单独的任务。

标签: java shell gradle


【解决方案1】:

以下内容在本地对我有用。

gradle -Dtest.single=MySuite clean test

这实际上使用了与--test 使用的更高级过滤方法不同的方法(测试包含)。

如引用链接中所述,上面的示例通过创建**/MySuite*.class 形式的文件包含模式来工作,而--test 尝试从扫描的测试集中选择测试。我怀疑在 Gradle 中实现的通用测试过滤与围绕 JUnit Suite 运行器的特定案例之间存在一些不可预见的交互。

话虽如此,即使是 Gradle 文档也警告说上述方法已被取代,实际上我可能会回应 @Opal 的评论并定义一个明确的任务来为给定的测试阶段运行套件。例如,使用gradle clean testSuite 运行的以下代码可能会运行集成套件。

task testSuite(type: Test) {
   include 'MySuite.class'  
}

参考文献:

【讨论】:

  • 如果你想确保你的测试运行,我会这样做:include '**/MySuite.class'
猜你喜欢
  • 2015-05-09
  • 1970-01-01
  • 1970-01-01
  • 2011-04-29
  • 1970-01-01
  • 2015-03-09
  • 2015-11-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多