Annotation Type TestResource
-
@ExtendWith(com.github.robtimus.junit.support.extension.testresource.TestResourceExtension.class) @Target({FIELD,PARAMETER,ANNOTATION_TYPE}) @Retention(RUNTIME) public @interface TestResource
TestResource
can 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
,Reader
orBufferedReader
the 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[]
,InputStream
orBufferedInputStream
,Encoding
can be used to change the encoding to use (defaults to UTF-8).In addition,
LoadWith
can be used to specify a method that is used to load the contents of the resource into an object, orEOL
can be used to define the line separator to use forString
,CharSequence
andStringBuilder
. This can be useful to create tests that work on different operating systems.It is illegal to:
- use
EOL
for automatic loading tobyte[]
,InputStream
,BufferedInputStream
,Reader
orBufferedReader
- use
EOL
in combination withLoadWith
- use
Encoding
in combination withLoadWith
whenLoadWith
defines a method that uses anInputStream
- use
Encoding
for automatic loading tobyte[]
,InputStream
orBufferedInputStream
- Author:
- Rob Spoor
- Since:
- 2.0
- use
-
-
Element Detail
-
value
String value
The resource to load.
-
-