【发布时间】:2014-10-20 19:57:13
【问题描述】:
我有一个多模块 maven 项目(ModuleA、ModuleB、ModuleC)
我在 ModuleA 中有一个测试
@ContextConfiguration(locations =
{ "file:../ModuleB/src/test/resources/application-context-test.xml",
"classpath:/mvc-dispatcher-servlet-test.xml"
})
从 ModuleB 中的文件加载上下文。
当我在 Eclipse 中运行测试时,它可以工作。但不是当测试由 maven 运行时。
在 Eclipse 中,当前路径设置为 ModuleA,但在 maven 中,它设置在父文件夹中。
所以我应该写:
文件:./ModuleB/src/test/resources/application-context-test.xml
在
文件:../ModuleB/src/test/resources/application-context-test.xml
让它在 maven 中工作(但它会破坏 eclipse)
谢谢!
如何告诉 maven(或 surefire 插件)运行相对于模块路径而不是父级的单元测试?
【问题讨论】:
-
为什么不使用
classpath而不是file? -
我试过了:"classpath:/application-context-test.xml" 但似乎这个文件不在类路径中。也许如果我将它从 ModuleB/src/main/resources/ 移到它会在类路径中......
-
Aggh... 错过了它位于测试文件夹中。
-
无论如何,让测试依赖于另一个模块测试不是一个好主意。
标签: spring maven spring-test maven-surefire-plugin