Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven test cannot find resources

I am trying to do maven test.

I have set resource directory

<testResources>
        <testResource>
            <directory>src/test/resources</directory>
        </testResource>
    </testResources>

I put a folder called inbound inside this directory. In my junit, I am trying to open it as new File("Inbound"), but it always cannot find it. I have have a inbound copy under my project root. The junit code cannot find it. Could any one please give me some suggestion? Thank you

like image 712
lucky_start_izumi Avatar asked May 01 '26 16:05

lucky_start_izumi


1 Answers

If you use src/test/resources, then you don't have to specify it in your pom.xml as it is the default resources path for tests.

Regarding your problem, you should not use new File("myfile"); but MyTestClass.class.getResourceAsStream("/myfile"); instead.

like image 173
Romain Linsolas Avatar answered May 04 '26 07:05

Romain Linsolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!