https://github.com/robtimus/junit-support
Contains interfaces and classes that make it easier to write unit tests with JUnit
https://github.com/robtimus/junit-support
java junit junit5 testing
Last synced: about 1 month ago
JSON representation
Contains interfaces and classes that make it easier to write unit tests with JUnit
- Host: GitHub
- URL: https://github.com/robtimus/junit-support
- Owner: robtimus
- License: apache-2.0
- Created: 2020-11-09T15:01:48.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-01-13T20:28:55.000Z (4 months ago)
- Last Synced: 2025-04-24T02:53:34.154Z (about 1 month ago)
- Topics: java, junit, junit5, testing
- Language: Java
- Homepage: https://robtimus.github.io/junit-support/
- Size: 3.96 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# junit-support
[](https://search.maven.org/artifact/com.github.robtimus/junit-support)
[](https://github.com/robtimus/junit-support/actions/workflows/build.yml)
[](https://sonarcloud.io/summary/overall?id=com.github.robtimus%3Ajunit-support)
[](https://sonarcloud.io/summary/overall?id=com.github.robtimus%3Ajunit-support)
[](https://snyk.io/test/github/robtimus/junit-support)Contains interfaces and classes that make it easier to write unit tests with [JUnit](https://junit.org/).
A quick overview of the functionality in this library:
## Injecting resources
Instead of having to write a utility method to read the contents of a resource, simply annotate a field, constructor parameter or method parameter with `@TestResource`, and JUnit will inject the resource for you:
```java
@Test
void testWithResource(@TestResource("input.json") String json) {
// use json as needed
}
```See [@TestResource](https://robtimus.github.io/junit-support/extension/test-resource.html) for more information, including options to configure how the resource is read or how to convert it to an object.
## Reconfigure static loggers
Loggers are often defined as `private static final` fields. That makes them difficult to mock. Using [@TestLogger](https://robtimus.github.io/junit-support/extension/test-logger.html) allows you to reconfigure these for test purposes.
## Disable logging for tests
[@DisableLogging](https://robtimus.github.io/junit-support/extension/disable-logging.html) allows you to suppress logging for tests.
## Disable logging for successful tests
[@LogOnFailure](https://robtimus.github.io/junit-support/extension/log-on-failure.html) allows you to suppress logging for successful tests but not for failed tests.
## Simplify writing JUnit extensions
If you want to write a JUnit extension that performs method lookups like [@MethodSource](https://junit.org/junit5/docs/current/api/org.junit.jupiter.params/org/junit/jupiter/params/provider/MethodSource.html), [MethodLookup](https://robtimus.github.io/junit-support/extension/method-lookup.html) provides an easy to use API.
If you want to write a JUnit extension that can inject values into fields, constructor parameters or method parameters, some [base classes](https://robtimus.github.io/junit-support/extension/injecting-extensions.html) are provided that let you focus on what's important - provide the values to inject.
## Predefined tests
This library mainly contains several [pre-defined tests](https://robtimus.github.io/junit-support/pre-defined-tests.html), defined in interfaces that each test one small aspect of a class or interface, often a single method. This makes it easier to test custom implementations of various common interfaces or base classes. The currently supported list is:
* [Collection](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/collections/CollectionTests.html), both modifiable and unmodifiable
* [Iterable](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/collections/IterableTests.html)
* [Iterator](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/collections/IteratorTests.html), both modifiable and unmodifiable
* [List](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/collections/ListTests.html) and [ListIterator](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/collections/ListIteratorTests.html), both modifiable and unmodifiable
* [Map](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/collections/MapTests.html) and [Map.Entry](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/collections/MapEntryTests.html), both modifiable and unmodifiable
* [Set](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/collections/SetTests.html), both modifiable and unmodifiable
* [Spliterator](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/collections/SpliteratorTests.html)
* [InputStream, OutputStream, Reader and Writer](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/io/package-summary.html)In addition, there are pre-defined tests for [MethodDelegation](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/DelegateTests.html) and [covariant return types](https://robtimus.github.io/junit-support/apidocs/com.github.robtimus.junit.support/com/github/robtimus/junit/support/test/CovariantReturnTests.html).
## Additional assertions
Several [additional assertions](https://robtimus.github.io/junit-support/additional-assertions.html) are provided. Some examples:
* alternatives to `assertTrue` and `assertFalse` that provide better failure messages
* assertions for checking the content of a `Reader` or `InputStream`
* assertions for `Optional`, `OptionalInt`, `OptionalLong` and `OptionalDouble`
* assertions for exception causes
* assertions for code that can can throw more than one different types of exceptions
* assertions for code that optionally throws an exception## Parameterized test support
[JUnit Pioneer](https://junit-pioneer.org/) has [@CartesianTest](https://junit-pioneer.org/docs/cartesian-product/) to provide the Cartesian product of sets of arguments. Using `@CartesianTest.MethodFactory` allows you to create argument sets programmatically. It does not provide the possibility to filter out combinations though. Class [ArgumentsCombiner](https://robtimus.github.io/junit-support/parameterized-test-support.html#argumentscombiner) works like JUnit Pioneer's `ArgumentSets` class but allows filtering out combinations.
## Testing concurrent code
Some classes for [testing concurrent code](https://robtimus.github.io/junit-support/testing-concurrent-code.html) are provided.