Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude certain test classes from a Gradle submodule

Tags:

java

gradle

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.

like image 983
gcoderx Avatar asked May 29 '26 19:05

gcoderx


1 Answers

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'
like image 130
user21909039 Avatar answered May 31 '26 08:05

user21909039



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!