marschall / memoryfilesystem-junit-provider

A Memoryfilesystem based @TempDir provider for JUnit
2 stars 1 forks source link
filesystem inmemory junit junit5 unit-testing

Memoryfilesystem JUnit Provider Maven Central Javadocs

A memoryfilesystem based @TempDir provider for JUnit 5.10+.

Only Path is supported, File can not be supported.

Usage

<dependency>
  <groupId>com.github.marschall</groupId>
  <artifactId>memoryfilesystem-junit-provider</artifactId>
  <version>1.0.1</version>
  <scope>test</scope>
</dependency>

You can either change individual elements annoated with @TempDir to use memoryfilesystem by use of the factory annotation value.

class SomeTests {

  @TempDir(factory = MemoryFileSystemTempDirFactory.class)
  Path tempDirectory;

  @Test
  void someTest() {
    Path input = Files.createFile(this.tempDirectory.resolve("input.txt"));
    // test code
  }

}

Alternatively you can also use the @MemoryTempDir meta-annotation.

class SomeTests {

  @MemoryTempDir
  Path tempDirectory;

  @Test
  void someTest() {
    Path input = Files.createFile(this.tempDirectory.resolve("input.txt"));
    // test code
  }

}

Global Configuration

You can also make all elements annoated with @TempDir to use memoryfilesystem by use of the junit.jupiter.tempdir.factory.default configuration property.

junit.jupiter.tempdir.factory.default=com.github.marschall.memoryfilesystem.junit.MemoryFileSystemTempDirFactory