从Gradle子模块中排除特定的测试类

huangapple go评论74阅读模式
英文:

Exclude certain test classes from a Gradle submodule

问题

在模块A中,我有一个包含编译其他模块B的模块。这是通过在模块A中添加以下行来完成的。

compile project(':B')

模块A和B都有它们自己的一组特定的测试类。

在从模块A运行gradle test时,我不希望执行模块B的某些测试类。

虽然我可以在模块B的gradle test任务中添加一个excludes块,但我想从模块A中执行此操作,以完全控制从模块A中的测试执行。

我已经尝试了在模块A中使用以下代码。

test {
   excludes = [
      "B/src/test/**"
   ]
}

但这似乎不起作用。

我可以知道我做错了什么吗?

模块A和B位于同一个文件夹中。

英文:

I have a module A which includes other module B at compilation. This has been done by adding the following line in module A.

compile project(':B')

Module A and B have their specific set of test classes.

While running gradle test from module A, I don't want certain test classes of Module B to get executed.

While I can add a excludes block in gradle test task of module B, I want to do this from module A to have full control on the test execution from module A.

I have already tried the following code in module A.

test {
   excludes = [
      "B/src/test/**"
   ]
}

But this doesn't seem to be working.

May I know what I am doing wrong?

Module A and B are located in the same folder.

答案1

得分: 1

当你执行 gradle test 时,gradle 会在每个子项目中运行名为 'test' 的任务。如果你只想测试 A 项目的类,可以使用 gradle A:test。这可能已经解决了你的问题。

如果你真的想在测试 A 时运行特定的测试,你可以在 B 项目中定义一个新的任务,然后在 A 的 test 任务中调用它。

// 放置在项目 B 中
tasks.register('myCustomTest', Test) {
  // 排除你想要的类
}
// 放置在项目 A 中
test.dependsOn 'B:myCustomTest'
英文:

When you issue gradle test, gradle will run the task named ‘test’ in every sub-project. If you only want to test A’s classes, you can issue gradle A:test instead. This might already solve your problem.

If you really want to run certain tests while testing A you can define a new task in B that you will call as part of A’s test task.

// place in project B
tasks.register('myCustomTest', Test) {
  // exclude the classes you want
}
// place in project A
test.dependsOn ‘B:myCustomTest'

huangapple
  • 本文由 发表于 2023年5月24日 19:36:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323099.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定