在Maven测试运行期间加载XML文件 [英] Loading XML Files during Maven Test run

查看:168
本文介绍了在Maven测试运行期间加载XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Maven构建环境中的Junit测试,我有一个关于使用资源文件(如XML等)的非常基本的问题。
这里有很少的相关问题,但这部分回答了我的问题。我希望有人可以为这个问题提供一个全面的回答。



我需要澄清


    如果我将资源文件保存在src / test / resources /下,在maven构建过程中将文件加载到单元测试中,那么我应该提供哪些文件系统路径? b $ b

  1. 同样的单元测试也由开发人员在自己的环境中运行,即不使用maven测试目标,并直接在Eclipse中使用运行配置。


支持这些运行方案并将文件保存在一个位置的最佳方法是什么?

解决方案

您应该使用 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

  1. 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?

  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆