javagradlebuild.gradle

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


I have my grade script set up. When I execute the Gradle build, everything is working and it runs the jUnit tests.

After that when I run the Gradle test I get the following:

C:\Users\..\..\Project>gradle test
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE

When I perform gradle clean, then Gradle build works, of course... I want to be able to reset only the tests, not build the whole project: how should I do this?


Solution

  • 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