# Stop rerunning your tests

DevFeed: [Stop rerunning your tests](<https://devfeed.tech/articles/stop-rerunning-your-tests-24695.md>)

Original publisher: [Read original article](<https://blog.gradle.org/stop-rerunning-tests>)

Author: Stefan Oehme

Published: 2018-09-08T04:00:00Z

Content type: opinion

Language: en

Sources: [The Gradle Blog](<https://devfeed.tech/sources/the-gradle-blog.md>)

Topics: [Gradle](<https://devfeed.tech/topics/gradle.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [mutation-testing](<https://devfeed.tech/topics/mutation-testing.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [build](<https://devfeed.tech/tags/build.md>), [features](<https://devfeed.tech/tags/features.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [mutation-testing](<https://devfeed.tech/tags/mutation-testing.md>), [tests](<https://devfeed.tech/tags/tests.md>), [time](<https://devfeed.tech/tags/time.md>)

## AI overview

This article explains why unnecessary test reruns waste development time and how Gradle's build cache and incremental build features can skip tests when their inputs have not changed. It recommends modeling non-deterministic inputs explicitly, including random seeds for randomized and mutation tests.

## Source excerpt

Tests are usually the longest running operation in your development process. Running them unnecessarily is the ultimate time waster. Gradle helps you avoid this cost with its build cache and incremental build features. It knows when any of your test inputs, like your code, your dependencies or system properties, have changed. If everything stays the same, Gradle will skip the test run, saving you a lot of time. So you can imagine my desperation when I see snippets like this on StackOverflow: tasks.withType(Test) { outputs.upToDateWhen { false } } Let's talk about what this means and why it is a bad idea. Communicating intent The above snippet just says "Never reuse this test's output". But why? Is it because there is some hidden input that Gradle doesn't know about? Or is it because the test produces random outputs? The reader can't tell. Deterministic tests don't need reruns "Insanity is doing the same thing over and over and expecting different results" - Not Albert Einstein The vast majority of your tests should be deterministic, i.e. given the same inputs they should produce the same result. If this is not the case, your project is in serious trouble. Stop reading this post and start fixing your code! Rerunning deterministic tests is a waste of your team's time. Non-deterministic tests There are a few reasons why you might want to rerun some tests in some cases even though none of the code changed. In these cases, you should model the additional input properly. Tell Gradle what exactly makes your tests non-deterministic. Randomized tests Some tests use randomization to improve the quality of your software. Random testing can be used to ensure that the production code can handle all kinds of inputs, not just the ones that the developer came up with. Mutation testing changes the production code in subtle way (e.g. introducing off-by-one errors) and checks whether your test suite catches these mistakes. Make this randomization explicit by making the random seed an