Kent Beck's test && commit || revert was an interesting and new approach at the end of 2018. Taking very small steps, allowing yourself to throw away code that didn't work and starting over, it's been fun to give that a try. Doing all the git ceremony around the workflow manually turned out to be quite tedious though. For Java & IntelliJ, there was no continuous test runner yet and using file watchers and bash scripts also didn't produce good results. While working on ApprovalTests.Java, I stumbled on a few JUnit4 runners around that topic. To use them with JUnit5, I learned about Extensions and that is how this project was born.
The easiest way to start a new project with this is by cloning the starter project.
dependencies {
testImplementation("com.larseckart:junit-tcr-extensions:0.0.1")
}
<dependency>
<groupId>com.larseckart</groupId>
<artifactId>junit-tcr-extensions</artifactId>
<version>0.0.1</version>
<scope>test</scope>
</dependency>
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.github.larseckart.tcr.TestCommitRevertExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ExtendWith(TestCommitRevertExtension.class)
class LibraryTest {
@Test
void testSomeLibraryMethod() {
assertEquals("42", "4" + "2");
}
}
I want to | Extension |
---|---|
... commit when tests pass, but not revert anything when they fail | CommitOnGreenExtension |
... commit when tests pass, revert when they fail | TestCommitRevertExtension |
... do TCR but don't bug me with commit messages | SilentTestCommitRevertMainExtension |
... do TCR but don't revert my tests, only my production code | TestCommitRevertMainExtension |
... do TCR without reverting my tests and I want it to be fast on macOS | FastTestCommitRevertMainExtension |
Code: @ExtendWith(<extension_from_above>.class)
- Does not support Gradle multi module projects
- Right now there is a lot of duplication, I expect a lot of refactoring. Luckily this won't influence the usage at all.
- No support yet to declare this extension for the whole test suit (at least I'm not aware).
- No GitHub actions yet to automate Ci and release