我目前有两个项目:
api-test
...
/config/config.json
...
和
ui-test
...
/config/config.json
...
在eclipse中,我在ui-test的构建路径中添加了api-test,因此api-test是ui-test的依赖。
然而构建失败了,因为api-test正在寻找位于api-test / config / config.json中的config.json:
System.getProperty("user.dir") + "/config/config.json"
在ui-test项目中不存在。
两个config.json包含不同的内容 - 当ui-test指的是api-test项目时,让每个项目引用自己的config.json的最佳解决方案是什么?
答案 0 :(得分:2)
按照Maven's Standard Directory Layout的建议将文件放入项目的src/main/resources
目录中。您可以使用相对路径来访问这些资源。
见How to get file resource from Maven src/test/resources/ folder in JUnit test?例如:
测试文件存在
@Test public void testStreamToString() { assertNotNull("Test file missing", getClass().getResource("/sample.txt")); ... }