【问题标题】:How to only run tests in a TestSuite class with gradle wrapper command如何使用 gradle wrapper 命令仅在 TestSuite 类中运行测试
【发布时间】:2018-12-11 11:09:11
【问题描述】:

我有一个 testSuite 类:

package com.company.tests;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

import com.company.tests.facing.CustomerTests;
import com.company.tests.backend.BookTests;
import com.company.tests.backend.ChargeTests;

@RunWith(Suite.class)
@Suite.SuiteClasses({
CustomerTests.class,
BookTests.class,
ChargeTests.class,
})

public class TestSuite {
}

我使用 gradle 包装器来运行测试,如下所示:

./gradlew test -PTestSuite

...但这会在 /src/test/java/com/company/tests/ 下运行 ALL 测试

有没有一种方法可以在命令行中使用 gradle wrapper 运行 TestSuite 类中的那些?我在stackoverflow上查看了其他问题,但无法解决,请举个例子。

【问题讨论】:

标签: java gradle junit gradlew


【解决方案1】:

这可以通过运行以下命令来实现:

./gradlew test --tests TestSuite

documentation 提供有关它支持的匹配类型的信息。 请注意,这假定 Gradle 4.7+

【讨论】:

  • 它不起作用。在 1 秒内完成,它将给出以下输出:BUILD SUCCESSFUL in 1s 4 actionable tasks: 2 executed, 2 up-to-date
  • 现在可以了。我必须确保 TestSuite 与其他测试位于同一目录级别。我把它放在一个叫做套件的文件夹下。否则它会运行 TestSuite 和它下面的所有其他程序。我使用的命令也是./gradlew :test --tests "*suite.TestSuite"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-27
  • 2015-08-27
  • 2018-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-31
相关资源
最近更新 更多