Class TemporaryDirectory

  • All Implemented Interfaces:
    org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource, ResourceFactory<java.nio.file.Path>

    public final class TemporaryDirectory
    extends java.lang.Object
    implements ResourceFactory<java.nio.file.Path>
    TemporaryDirectory is a "resource factory" implementation that, combined with @New or @Shared, allows for the creation of temporary directories that can be used by individual tests or shared across multiple tests.

    When used with the @New annotation and the annotation's arguments field is populated, the first argument will be used as the prefix of the name of the temporary directory.

    It is part of the "resources" JUnit Jupiter extension, which pertains to anything that needs to be injected into tests and which may need to be started up or torn down. Temporary directories are a common example.

    This class is intended for users.

    For more details and examples, see the documentation on resources and temporary directories.

    Since:
    1.9.0
    See Also:
    ResourceFactory, New, Shared
    • Constructor Detail

      • TemporaryDirectory

        public TemporaryDirectory()
    • Method Detail

      • create

        public Resource<java.nio.file.Path> create​(java.util.List<java.lang.String> arguments)
                                            throws java.lang.Exception
        Description copied from interface: ResourceFactory
        Returns a new resource.
        Specified by:
        create in interface ResourceFactory<java.nio.file.Path>
        Parameters:
        arguments - a list of strings to be used to populate or configure the resource
        Throws:
        java.lang.Exception - if creating the resource failed