How to run Gradle test when all tests are UP-TO-DATE?

gradle test --rerun-tasks

Specifies that any task optimization is ignored.

Source: https://gradle.org/docs/current/userguide/gradle_command_line.html


One option would be using the --rerun-tasks flag in the Forcing tasks to execute section. This would rerun all the the test task and all the tasks it depends on.

If you're only interested in rerunning the tests then another option would be to make gradle clean the tests results before executing the tests. This can be done using the cleanTest task.

Some background - the Java plugin defines a clean tasks to each of the other tasks. According to the Tasks documentation:

cleanTaskName - Deletes files created by specified task. cleanJar will delete the JAR file created by the jar task, and cleanTest will delete the test results created by the test task.

Therefore, all you need in order to re-run your tests is to also run the cleanTest task, i.e.:
gradle cleanTest test


Other option would be to add following in your build.gradle:

test.outputs.upToDateWhen {false}