Can't load ResourceBundle during junit test

若如初见. 提交于 2019-12-07 07:57:14

问题


I'm trying to write some Junit tests to test old classes in our app. The code is trying to load a ResourceBundle (for translations) but fails. I guess the problem is classpath related but I can't figure it out.

The code is laid out in /src and my tests are in /test. The ResourceBundles are loaded given a base name relative to /src, say, "foo/bar/baz".

My tests use the same classpath as the app itself, so I don't understand why it won't find the bundles.

Any ideas to what's wrong?


回答1:


Resources are not resolved from the source folder but from the class directory. Are your resource files copied to the output folder (bin, target/classes etc.) ? If not, your classes can't find them.




回答2:


If you are using maven, you typically want to put all kind of properties files and resource bundles in a separate source folder called src/main/resources/.

If you want to override values in your unit tests then you can add a duplicate prop. file in the src/test/resources source folder.



来源:https://stackoverflow.com/questions/3727149/cant-load-resourcebundle-during-junit-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!