开发者

Where do I put properties files for running JUnit tests on Maven?

开发者 https://www.devze.com 2023-03-05 05:46 出处:网络
I\'m using Maven 3.0.3.I\'m running the \"mvn test\" command, in which my test files are in the standard place (src/test/java).Where do I put properties files so that they get picked up by Java\'s \"g

I'm using Maven 3.0.3. I'm running the "mvn test" command, in which my test files are in the standard place (src/test/java). Where do I put properties files so that they get picked up by Java's "getResourceAsStream" method? I tried placing my properties files in both src/main/resources and src/test/resources, but my JUnit test isn't finding th开发者_开发百科em. Here's how I want to load the tests ...

final InputStream in = getClass().getResourceAsStream("my.properties");

but this returns null. I'm using JUnit 4.8. Any ideas? Thanks, - Dave


It works for me if I use getClass().getResourceAsStream("/my.properties").

Without the / prefix, the path is relative to your class's package, so you'd have to put the properties file in a path like src/test/resources/com/mycompany/mypackage/my.properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消