Annotation Type TempDir
@TempDir
can be used to annotate a member field of type File
, Path
,
or untyped like def
/Object
in a spec class (untyped field will be injected with Path
).
Alternatively, you can use it with any class that has a public constructor with a single File
or Path
parameter, like FileSystemFixture
this way you can use your own utility classes for file manipulation.
If the annotated field is shared, the temp directory will be shared in this spec, otherwise every iteration will have its own temp directory.
Example:
@TempDir
File testFile // will inject a File
@TempDir
Path testPath // will inject a Path
@TempDir
def testPath // will inject a Path
@TempDir
FileSystemFixture fsFixture // will inject an instance of FileSystemFixture with the temp path injected via constructor
Since Spock 2.4, @TempDir
can be used to annotate a method parameter, with the same behavior as the field types.
Use this if you want to use a temp directory in a single method only.
Valid methods are setup()
, setupSpec()
, or any feature methods.
- Since:
- 2.0
-
Nested Class Summary
Nested Classes -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionWhether to cleanup the directory after the test. -
Field Summary
Fields
-
Field Details
-
TEMP_DIR_CLEANUP_PROPERTY
- See Also:
-
-
Element Details
-
cleanup
TempDir.CleanupMode cleanupWhether to cleanup the directory after the test.- Since:
- 2.3
- Default:
- DEFAULT
-