Run only changed test classes


(Sverre Moe) #1

Gradle runs all tests, even those that hasn’t been changed since last time I ran gradle test.
Is this expected behavior? It does not seem very efficient.

If I change just one JUnit test class and run gradle test, it should avoid running the other test classes.

Using Gradle 4.9
JUnit 4
I have a mix of both JUnit 5 and JUnit 4 test classes.


(Chris Doré) #2

While not as convenient as some sort of auto filtering, you can manually filter which tests to run from the command line.
https://docs.gradle.org/current/userguide/java_testing.html#simple_name_pattern


(Sverre Moe) #3

Yes, I know, but it is a lot more cumbersome than just running “gradle test”. Specially if there are more than one test classes that has changed, and perhaps some test classes in different packages.

The compile and test compile only compiles classes that have changed since last time.
It would have been great to get gradle to run only the test classes that has changed.

Perhaps with a flag to determine full or changed.

gradle test --full
gradle test --changed

(Stefan Oehme) #4

The compile and test compile only compiles classes that have changed since last time.

That’s not quite true, they also compile anything affected by that change, otherwise it wouldn’t be correct.

To do this correctly with tests, we’d have to collect execution data to see which classes are used during each test. This is pretty invasive, but would ultimately allow us to only rerun affected tests even on production code changes. The holy grail of incremental feedback if you wish :wink: Nothing in that direction is planned at the moment, though technically someone could build this in a 3rd party plugin, at least as a proof of concept.