Annotation Type TestWithResources
-
@Target(TYPE) @Retention(RUNTIME) @ExtendWith(TestWithResourcesExtension.class) @Inherited @Documented @API(status=EXPERIMENTAL, since="0.1") public @interface TestWithResources
TestWithResourcesis a JUnit Jupiter extension that supplies your tests with loaded and parsed content of resource files.TestWithResourcesextension finds all fields and test method parameters annotated withGiven*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
@TestWithResourcescan 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."); } }