Skip to content

JUnit 5 extension for Kent Beck's test commit revert workflow.

License

Notifications You must be signed in to change notification settings

LarsEckart/tcr-extension

Repository files navigation

test Maven Central

tcr-extension

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.

How to get it

Starter Project

The easiest way to start a new project with this is by cloning the starter project.

Gradle

dependencies {
    testImplementation("com.larseckart:junit-tcr-extensions:0.0.3")
}

Maven

<dependency>
  <groupId>com.larseckart</groupId>
  <artifactId>junit-tcr-extensions</artifactId>
  <version>0.0.3</version>
  <scope>test</scope>
</dependency>

Examples

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");
  }
}

Which extension should I use?

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)

Limitations

  • 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

LICENSE

Apache 2.0 License

Questions?

Reach out on twitter: @LrsEckrt or publish an issue.

About

JUnit 5 extension for Kent Beck's test commit revert workflow.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages