https://github.com/fhofherr/junit5-class-source
@ClassSource annotation for Juni5 parameterized tests
https://github.com/fhofherr/junit5-class-source
java junit5 parameterized-tests testing
Last synced: 3 months ago
JSON representation
@ClassSource annotation for Juni5 parameterized tests
- Host: GitHub
- URL: https://github.com/fhofherr/junit5-class-source
- Owner: fhofherr
- License: mit
- Created: 2018-10-28T10:14:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-06T14:51:39.000Z (about 6 years ago)
- Last Synced: 2025-01-05T09:42:42.665Z (5 months ago)
- Topics: java, junit5, parameterized-tests, testing
- Language: Java
- Size: 62.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# junit5-class-source
[](https://travis-ci.org/fhofherr/junit5-class-source)
A simple `@ClassSource` annotation to use with
[JUnit5](https://junit.org) [parameterized
tests](https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests).## Example
```java
...@ParameterizedTest
@ClassSource(SampleDataProvider.class)
void showClassSourceUsage(SampleData data) {
assertTrue(asList("value1", "value2").contains(data.value));
}...
private static class SampleDataProvider implements TestDataProvider {
@Override
public Stream provideTestData() {
return Stream.of(
new SampleData("value1"),
new SampleData("value2"));
}
}private static class SampleData {
String value;SampleData(String value) {
this.value = value;
}
}
```## Rationale
I really love to use the [parameterized
tests](https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests)
feature of JUnit5. Mostly I use the `@MethodSource`. However, often I wish
I could specify the source my test data in a more refactoring-save way instead
of a string pointing to a method in a class.The `@ClassSource` allows me to do just this. Instead of a string I specify
a class. I don't have to bother about updating the string (or count on my IDE
doing it) when I decide to refactor my sources.## License
Copyright © 2018 Ferdinand Hofherr
Distributed under the MIT License.