Klunk
Klunk

Reputation: 825

Running a subset of tests in Gradle

I have a multiproject gradle build which contains a mix of Java with JUnit and Scala with Specs tests, plus a few other technologies.

I have pretty much everything building fine but I am hitting an issue with the tests.

My projects are all organised with the following structure

<project>/src/main/... - containing the production source code
<project>/src/tests-unit/... - containing the JUnit or Specs test code

and then optionally a combination of

<project>/src/tests-util/... - containing utility classes for setting up tests
<project>/src/tests-functional/... - containing functional level test code
<project>/src/tests-integration/... - containing integration level test code

My problem is that running grade tests on this project will actually run the tests in all the test directories and I want to be able to control what tests are being run. I had the idea of setting up a separate task for each level of test, but how do I specify to just run tests in the /src/tests-unit hierarchy and ignore the others?

I have tried several things including setting the runtimeClasspath of the sourceset for a target but I just get a deprecation warning for this and it has no effect.

Many thanks

Upvotes: 2

Views: 973

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

You'd typically declare separate source sets and separate Test tasks. See samples/java/withIntegrationTests in the full Gradle distribution for details.

Upvotes: 1

Related Questions