Package spock.lang

Annotation Type TempDir

  • @Beta
    public @interface TempDir
    Generate a temp directory for test, and delete it after test.

    @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.


     File testFile // will inject a File
     Path testPath // will inject a Path
     def testPath // will inject a Path
     FileSystemFixture fsFixture // will inject an instance of FileSystemFixture with the temp path injected via constructor