All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spock.lang.TempDir Maven / Gradle / Ivy

Go to download

Spock is a testing and specification framework for Java and Groovy applications. What makes it stand out from the crowd is its beautiful and highly expressive specification language. Thanks to its JUnit runner, Spock is compatible with most IDEs, build tools, and continuous integration servers. Spock is inspired from JUnit, jMock, RSpec, Groovy, Scala, Vulcans, and other fascinating life forms.

There is a newer version: 2.4-M4-groovy-4.0
Show newest version
package spock.lang;

import org.spockframework.runtime.extension.ExtensionAnnotation;
import org.spockframework.runtime.extension.builtin.TempDirExtension;
import org.spockframework.util.Beta;
import spock.util.io.FileSystemFixture;

import java.io.File;
import java.lang.annotation.*;
import java.nio.file.Path;

/**
 * Generate a temp directory for test, and delete it after test.
 *
 * 

* {@code @TempDir} can be used to annotate a member field of type {@link File}, {@link Path}, * or untyped like {@code def}/{@link Object} in a spec class (untyped field will be injected with {@code Path}). *

* Alternatively, you can use it with any class that has a public constructor with a single {@link File} or {@link Path} * parameter, like {@link 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
 * 
* * @author dqyuan * @since 2.0 */ @Beta @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @ExtensionAnnotation(TempDirExtension.class) public @interface TempDir { }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy