在Maven测试运行期间加载XML文件 [英] Loading XML Files during Maven Test run
问题描述
这里有很少的相关问题,但这部分回答了我的问题。我希望有人可以为这个问题提供一个全面的回答。
我需要澄清
-
同样的单元测试也由开发人员在自己的环境中运行,即不使用maven测试目标,并直接在Eclipse中使用运行配置。
如果我将资源文件保存在src / test / resources /下,在maven构建过程中将文件加载到单元测试中,那么我应该提供哪些文件系统路径? b $ b
支持这些运行方案并将文件保存在一个位置的最佳方法是什么?
您应该使用 Class.getResourceAsStream(),以便您不依赖于文件路径。
阅读此图片:访问资源
I have a very basic question on usage of resource files (like XML etc.) for Junit tests in a Maven build environment. There were few related questions to this topic here but it answered my question only partly. I am hoping someone can give a comprehensive answer for this issue
I need clarification on
If I keep my resource files under src/test/resources/, to load this file in my unit test during maven build, what is file system path I should provide?
The same unit tests are also run at an individual level by developers in their own environments i.e. Without using maven test goal and directly using a run config in Eclipse.
What is the best way to support both these run scenario and keeping the files in a single location?
You should use Class.getResourceAsStream() so that you are not depend upon the file paths.
Read this turorial: Accessing Resources
这篇关于在Maven测试运行期间加载XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!