-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,37 @@ | ||
[![Build status](https://github.com/schmonz/junit-greencently/actions/workflows/main-build.yml/badge.svg)](https://github.com/schmonz/junit-greencently/actions/workflows/main-build.yml) | ||
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.schmonz/junit-greencently/badge.svg?gav=true)](https://central.sonatype.com/artifact/com.schmonz/junit-greencently) | ||
|
||
# Greencently | ||
|
||
For teams whose commits fail on red tests, Greencently offers an optimization: | ||
the pre-commit hook can know when you've run all tests green "recently enough". | ||
Team chooses policy. | ||
|
||
## Benefits (immediate) | ||
|
||
- Lower-friction commits | ||
- Time and energy saved | ||
|
||
## Benefits (speculative) | ||
|
||
Probably you'll lean into smaller, more frequent commits. | ||
Maybe you'll also feel more able to invest in further test speedups. | ||
|
||
## Usage | ||
|
||
Nobody needs to learn anything. | ||
The pre-commit hook still has your back when you forget to... | ||
|
||
- Run any tests | ||
- Run all tests | ||
- Attend to red tests | ||
|
||
With Greencently, the pre-commit hook also has your back when you _remember_. | ||
|
||
All tests green, recently? | ||
Commit quickly and stay in flow. | ||
# [Greencently](https://schmonz.com/software/greencently) | ||
|
||
## Setup | ||
|
||
- [Documentation](https://schmonz.com/software/greencently) | ||
For JUnit 5: | ||
|
||
1. Update `build.gradle.kts`: | ||
```gradle | ||
dependencies { | ||
testRuntimeOnly("com.schmonz:junit-greencently:VERSION_NUMBER_HERE") | ||
} | ||
tasks.withType<Test> { | ||
jvmArgs("-Djunit.jupiter.extensions.autodetection.enabled=true") | ||
maxParallelForks = 1 // see #4 | ||
} | ||
``` | ||
2. Run all tests for project | ||
3. If green, observe top-level `.when-all-tests-were-green-junit5` | ||
4. Append to top-level `.gitignore`: `*when-all-tests-were-green*` | ||
5. In pre-commit hook, inspect file modification time. Example: | ||
```sh | ||
#!/bin/sh | ||
all_tests_were_recently_green() { | ||
thenstamp=$(date -r .when-all-tests-were-green-junit5 '+%s' 2>/dev/null || echo 0) | ||
nowstamp=$(date '+%s') | ||
secondsago=$(expr ${nowstamp} - ${thenstamp}) | ||
[ ${secondsago} -lt 30 ] | ||
} | ||
if all_tests_were_recently_green; then | ||
./gradlew clean build -x test | ||
else | ||
./gradlew clean build | ||
fi | ||
``` |