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:junit-greencently:CHECK_ABOVE_FOR_VERSION")
}
tasks.withType<Test> {
maxParallelForks = 1 // see issue #4
}
- Run all tests in project
- If green, observe top-level timestamp file
.greencently-junit5
- Append to top-level
.gitignore
:*greencently*
- Observe
git status
not showing timestamp file - In pre-commit hook, inspect file modification time. Example:
#!/bin/sh
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 30; then
./gradlew clean build -x test
else
./gradlew clean build
fi
See the Greencently webpage.