Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/unruly/junit-rules
A collection of useful JUnit rules from Unruly's codebases
https://github.com/unruly/junit-rules
java junit junit-rule tdd
Last synced: about 1 month ago
JSON representation
A collection of useful JUnit rules from Unruly's codebases
- Host: GitHub
- URL: https://github.com/unruly/junit-rules
- Owner: unruly
- License: mit
- Created: 2014-10-16T15:09:48.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-03-21T14:42:03.000Z (almost 7 years ago)
- Last Synced: 2024-03-25T13:10:24.330Z (10 months ago)
- Topics: java, junit, junit-rule, tdd
- Language: Java
- Homepage: http://tech.unruly.co/junit-rules/
- Size: 43 KB
- Stars: 17
- Watchers: 22
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
junit-rules
===========[![Build Status](https://travis-ci.org/unruly/junit-rules.svg?branch=master)](https://travis-ci.org/unruly/junit-rules)
A collection of useful JUnit rules from Unruly's codebases
## Install from Maven Central
```xml
co.unruly
junit-rules
1.1```
## Ignore tests until a certain date or datetime.
This allows you to write an acceptance/integration test before implementing a feature, and integrate it into your codebase before the implementation is complete.
`@IgnoreUntil` must be present on the test method you wish to ignore.
The date/datetime value of the class level annotation can be shared across methods in the class or overridden by the method annotation.
```java
@IgnoreUntil("2099-01-01")
public class MyIgnorableTest {@Rule public IgnoreUntilRule rule = new IgnoreUntilRule();
@IgnoreUntil
@Test
public void ignoredUntil20990101() {
}@IgnoreUntil
@Test
public void alsoIgnoredUntil20990101() {
}@IgnoreUntil("2014-10-30")
@Test
public void ignoredUntil20141030() {
}@IgnoreUntil("2014-10-30T17:30:00")
@Test
public void ignoredUntil20141030T173000() {
}@Test
public void notIgnored() {
}
}
```The class annotation is optional, you can just annotate the method.
```java
public class MyIgnorableTest {
@Rule public IgnoreUntilRule rule = new IgnoreUntilRule();
@IgnoreUntil("2014-10-30T17:30:00")
@Test
public void ignoredUntil20141030T173000() {
}@Test
public void notIgnored() {
}
}
```## Quarantine non-deterministic tests
```java
@Rule QuarantineRule rule = new QuarantineRule();@NonDeterministic(retries=3)
public void some_sporadically_failing_test() {}
```QuarantineRule supports a functional interface called QuarantineRuleLogger as a constructor argument for additional logging capabilities. For example, we email ourselves failures so it's harder to ignore.
```java
@Rule QuarantineRule rule = new QuarantineRule(msg -> System.err.println(msg));
```## Make sure tests pass reliably
We use this to diagnose tests as being non-deterministic. To run each test 10 times:
```java
@Rule ReliabilityRule rule = new ReliabilityRule(10);
```