Languages
[Edit]
EN

Java / Spring boot - unit test resource path

6 points
Created by:
isherwood
299

Quick solution:

private static final Path TEST_RESOURCES = Paths.get("src/test/resources");

Practical unit test example:

import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

class ExampleUnitTest {

    private static final Path TEST_RESOURCES = Paths.get("src/test/resources");

    @Test
    void unitTestExample() throws IOException {

        Path textDataPath =  TEST_RESOURCES.resolve("some_data").resolve("text_data.txt");

        List<String> textData = Files.readAllLines(textDataPath);

        // ...
    }
}

 

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join