Annotation Type TestWithResources
@Target(TYPE) @Retention(RUNTIME) @ExtendWith(TestWithResourcesExtension.class) @Inherited @Documented @API(status=EXPERIMENTAL, since="0.1") public @interface TestWithResources
TestWithResources is a JUnit Jupiter extension that supplies your tests with loaded and parsed content of
resource files.
TestWithResources extension finds all fields and test method parameters annotated with
Given*Resource (a.k.a resource annotations) and sets their values to loaded and parsed content of
requested resource files.
In some cases, resource injection requires an object (called parser), that will perform parsing of resource.
Those objects, provided by fields or methods annotated with With* (a.k.a parser annotations) are
discovered by extension prior to resource parsing.
The annotation @TestWithResources can be used on a superclass in the test hierarchy as well. All
subclasses will automatically inherit support for the extension.
Example:
@TestWithResources
class InjectTextResourcesTests {
@GivenTextResource("/com/adelean/junit/jupiter/resource.txt")
String instanceField;
@Test
public void testInjectTextIntoStringInstanceField() {
assertThat(instanceField)
.isEqualTo("The quick brown fox jumps over the lazy dog.");
}
}