How to run multiple test classes in gradle that are not in the same package?

I have the following class tests.

  1. com.baz.bar.Foo

  2. com.bar.foo.Baz

  3. com.foo.baz.Bar

I want to execute com.baz.bar.Foo and com.bar.foo.Baz . I know how to execute all of them and how to execute one of them. I do not know how to execute any arbitrary set between.

+7
source share
2 answers

This is easy to do in the build script:

 test { filter { filterTestsMatching "com.baz.bar.Foo", "com.bar.foo.Baz", ... } } 

command line equivalent is gradle test --tests com.baz.bar.Foo (or just --tests Foo ), but from what I can say, only one class is supported here (more precisely, one template).

If you need the ability to pass multiple templates, you can script it yourself. For example, you can read the system property passed from the command line via -Dtest.filter=Foo,Bar,Baz , split the value into separate parts and pass them to filterTestsMatching .

Reinforcing --tests to support comma-separated values ​​can make a good pull request for a Gradle project.

+4
source

Gradle supports several --tests , i.e.

 gradle test --tests com.baz.bar.Foo --tests com.bar.foo.Baz --tests com.foo.baz.Bar 

will do what you want

+4
source

Source: https://habr.com/ru/post/973334/


All Articles