Spring Boot version 2.3.x src/test/resources removed

Viewed 640

Seems in the Springboot version 2.3.x , they have removed the src/test/resources folder ,

I downloaded a skeleton from start.spring.io and did not see it , the current project structure is as below , in such a case how do I use a test specific property file , problem is even if I create a src/test/resources folder and put a test.property file in it , its not being found while I am running the test , Any help is greatly appreciated.

enter image description here

Options I chose while generating the skeleton project in start.spring.io

enter image description here

2 Answers

After a fair amount of research I found my answer , so the "resources" folder under src/test has been removed as part of the skeleton project that we could download from start.spring.io , but now they have included a new build task , well my project is in gradle but I am sure such is the case with Maven too , the name of this task in gradle is "processTestResources" , it copies whatever you have inside your src/test/resources folder to the <Project_HOME>/build/resources/test , which is in the classpath and you can access your resources as you could earlier , the only things is now you have to manually create the "resources" folder , now issue resolved , Thanks everyone for your inputs.

enter image description here

What IDE are you using ? Does the project use Maven ? In Eclipse with Maven if you right click on src/test and choose New -> Source Folder, and call it resources it should be created and added to the test classpath by Maven.

enter image description here

After placing the appropriate files in src/main/resources, and src/test/resources and running

    try(final Stream<String> fileStreamFromClasspath = Files.lines(Path.of(ClassLoader.getSystemResource("test.file").toURI())))
    {
        fileStreamFromClasspath.forEach(l -> System.out.println(l)); // NOSONAR
    }
    try(final Stream<String> fileStreamFromFilesystem = Files.lines(Path.of(("src/main/resources/test.file"))))
    {
        fileStreamFromFilesystem.forEach(l -> System.out.println(l)); // NOSONAR
    }
    try(final Stream<String> testFileStreamFromFilesystem = Files.lines(Path.of(("src/test/resources/test.file"))))
    {
        testFileStreamFromFilesystem.forEach(l -> System.out.println(l)); // NOSONAR
    }

Produces output:

This is the test test file.
This is the main test file.
This is the test test file.
Related