Annotation Type TestResource
-
@ExtendWith(com.github.robtimus.junit.support.extension.testresource.TestResourceExtension.class) @Target({FIELD,PARAMETER,ANNOTATION_TYPE}) @Retention(RUNTIME) public @interface TestResource
TestResourcecan be used to annotate a field or a parameter in a lifecycle method or test method that should be resolved into the contents of a (test) resource. The resource will be loaded relative to the class where the field, constructor or method is defined.The following field / parameter types are supported by default:
When the type isInputStream,BufferedInputStream,ReaderorBufferedReaderthe contents can only be read once. It is therefore advised to only use this for test method parameters. When the injected stream or reader goes out of scope it will be automatically closed.When the type is not
byte[],InputStreamorBufferedInputStream,Encodingcan be used to change the encoding to use (defaults to UTF-8).In addition,
LoadWithcan be used to specify a method that is used to load the contents of the resource into an object, orEOLcan be used to define the line separator to use forString,CharSequenceandStringBuilder. This can be useful to create tests that work on different operating systems.It is illegal to:
- use
EOLfor automatic loading tobyte[],InputStream,BufferedInputStream,ReaderorBufferedReader - use
EOLin combination withLoadWith - use
Encodingin combination withLoadWithwhenLoadWithdefines a method that uses anInputStream - use
Encodingfor automatic loading tobyte[],InputStreamorBufferedInputStream
- Author:
- Rob Spoor
- Since:
- 2.0
- use
-
-
Element Detail
-
value
String value
The resource to load.
-
-