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?
Also, having to add
--rerun-tasks
is really redundant. Never happens. Create a--no-rerun-tasks
and make--rerun-tasks
default whencleanTask
Other option would be to add following in your build.gradle:
Here's a solution using the "build.gradle" file, in case you don't want to modify your command line:
And here's the output. Notice 2 changes from your previous output:
1) A new 'cleanTest' task appears in the output.
2) 'test' is always cleaned (i.e. never 'UP-TO-DATE') so it gets executed every time:
This was recently the topic on Gradle's blog post Stop rerunning your tests. The author shows an example using
outputs.upToDateWhen { false }
and explains why it is wrong:Then, the author goes on to explain why rerunning some tests is a waste of time:
In the few cases where you do want to rerun tests where the code has not changed, you should model them as an input. Here are both examples from the blog post that show adding an input so the task will use it during its up-to-date checks.
I recommend reading the entire blog post.
gradle test --rerun-tasks
Source: https://gradle.org/docs/current/userguide/gradle_command_line.html
One option would be using the
--rerun-tasks
flag in the command line. 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 documentation:
Therefore, all you need in order to re-run your tests is to also run the
cleanTest
task, i.e.:gradle cleanTest test