问题描述
我正在尝试编写一些Junit测试来测试我们应用中的旧类。代码正在尝试加载ResourceBundle(用于翻译)但失败了。我想问题是类路径相关但我无法弄明白。
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.
代码在/ src中布局,我的测试在/ test中。在给定相对于/ src的基本名称的情况下加载ResourceBundle,比如foo / bar / baz。
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".
我的测试使用与app本身相同的类路径,所以我不明白为什么它找不到捆绑包。
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?
推荐答案
资源不是从源文件夹解析,而是从类目录解析。您的资源文件是否已复制到输出文件夹(bin,target / classes等)?如果没有,你的课程找不到它们。
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.
这篇关于在junit测试期间无法加载ResourceBundle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!