Do you usually run your tests before you commit, to check your work?
Do your tests also get run by a pre-commit hook?
This is helpful in the worst case -- the pre-commit hook has your back when you forget -- but in the typical case it's harmful:
- Disrupts flow
- Doubles cost
- Adds no marginal benefit
- Discourages frequent small well-tested commits
- Engenders learned helplessness
We can fix this.
- Update
build.gradle.kts
:
dependencies {
testRuntimeOnly("com.schmonz:greencently:CHECK_ABOVE_FOR_VERSION")
}
tasks.withType<Test> {
maxParallelForks = 1 // see issue #4
}
- Run all tests in your project
- If green, see that
.greencently/junit5
exists (and it's already.gitignore
'd) - Run only one test, or only some tests, or all tests where at least one of them is red
- See that
.greencently/junit5
no longer exists - From now on, whenever you've just run tests, all of them, and they're all green, the pre-commit hook can decide not to run them again. Example:
#!/bin/sh
ACCEPTABLY_LARGE_NUMBER_OF_SECONDS_AGO=30
greencently() {
too_many_seconds_ago=$1
thenstamp=$(date -r .greencently/junit5 '+%s' 2>/dev/null || echo 0)
nowstamp=$(date '+%s')
secondsago=$(expr ${nowstamp} - ${thenstamp})
[ ${secondsago} -lt ${too_many_seconds_ago} ]
}
if greencently ${ACCEPTABLY_LARGE_NUMBER_OF_SECONDS_AGO}; then
./gradlew clean build --exclude-task test
else
./gradlew clean build
fi
See the Greencently webpage.