【问题标题】:No tests found when filtering junit test suite过滤junit测试套件时未找到测试
【发布时间】:2016-01-22 01:59:50
【问题描述】:

我想运行一个 junit4 测试套件并使用 build.gradle 中的过滤器指定它,但 gradle(2.10 版) 找不到测试。 有没有办法在 gradle 中运行指定的 junit 测试套件?

我的测试套件类

@RunWith(Suite.class) @SuiteClasses({ TestFoo.class, TestBar.class }) 公共类 MyTestSuite { }

build.gradle

测试 { 筛选 { includeTestsMatching "*MyTestSuite" } }

【问题讨论】:

标签: testing gradle filter suite


【解决方案1】:

DSL documentation 中的示例使用 include 代替:

test {
  // explicitly include or exclude tests
  include 'org/foo/**'
  exclude 'org/boo/**'
}

【讨论】:

  • 是的,包括工作。(在我的情况下,通过添加行 include '**/MyTestSuite.class')。过滤器只是不适用于 junit 测试套件?
【解决方案2】:

filter 可能意味着与 include 和 exclude 结合使用。 Doc 说:允许过滤执行测试

所以如果你只想运行一个方法 foo:

test {
  include '**MyTestSuite.class'
  filter {
            includeTestsMatching "*TestBar.foo"
  }
}

【讨论】:

    猜你喜欢
    • 2023-04-06
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多