0

我有一个项目如下:

Project
    Project-A/
        src/test/java/
            someTests.java
        src/test/resources
            database/
                create.sql
                insert.sql
            spring/
                test-config.xml
    project-B/
        src/test/java
            otherTests.java

项目-B 的pom.xml

<dependency>
    <groupId>${project.groupId}</groupId>
    <artifactId>Project-A</artifactId>
</dependency>

someTests.java中,我的配置是:

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/webapp-config.xml", "classpath:spring/test-dao-config.xml" })
public class DacsDAOImplTest

我想在 otherTests.java 中重用test - config.xmlcreate.sqlinsert.sql

我已经在 otherTests.java 中尝试过

@ContextConfiguration(locations = {"classpath*:spring/test-dao-config.xml"})

但这似乎不起作用...

编辑:Geoand 的回答帮助,我没有更多与豆类有关的例外,但现在我有一个

FileNotFoundException:类路径资源 [exception-messages.properties] 无法打开,因为它不存在。

由于我不完全了解所做的更改,因此我不知道如何解决此问题... webapp-config.xml中使用异常消息作为<context:property-placeholder location="classpath:exception-messages.properties" />

4

1 回答 1

1

我认为问题在于,尽管您将 Project-A 导入到 Project-B 中,但 Maven 并未包含测试代码。查看这个SO question 中的解决方案,看看它是否有帮助

编辑:

一旦你让 maven 也可以导入测试代码,你需要在 /test/resources 下创建 .properties 文件,其中包含你在应用程序中使用的属性的测试值

于 2014-04-07T16:52:40.000 回答