如何设置 Maven 在运行测试时覆盖另一个设置文件?
请参阅以下 Maven 生成的项目
target
classes
test-classes
src
main
java
scripts
resources
datasource-settings.xml
test
java
resources
datasource-settings.xml
,我希望运行测试时使用 test/resources/datasource-settings.xml 中找到的设置,而不是 main/resources/datasource-settings.xml。是否可以 ?如果是这样,我应该怎样做才能实现我的目标?
See the following Maven generated project
target
classes
test-classes
src
main
java
scripts
resources
datasource-settings.xml
test
java
resources
datasource-settings.xml
I would like, when running a test, to use the settings found in test/resources/datasource-settings.xml instead of main/resources/datasource-settings.xml. Is it possible ? If so, what should i do to get my goal ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
放置在
${basedir}/src/test/resources
(默认位置)中的资源将自动添加到 Maven 为单元测试设置的类路径中,并优先于放置在中的资源>${basedir}/src/main/resources
。所以你想要做的实际上只是默认行为。Resources placed in
${basedir}/src/test/resources
(the default location) will be automatically added to the class path set up by Maven for your unit tests and take precedence over resources placed in${basedir}/src/main/resources
. So what you want to do is actually just the default behavior.如果您尚未修改 POM 中的资源设置,则测试资源应首先显示在您的类路径中,因此测试应在主文件之前找到该文件,而无需执行任何额外操作。您看到什么样的行为?
If you haven't modified the resource settings in your POM, the test resources should show up in your classpath first, so a test should find that file before the main one without you needing to do anything extra. What sort of behavior are you seeing?