【问题标题】:Reuse resources and context in another project在另一个项目中重用资源和上下文
【发布时间】:2014-04-07 16:42:16
【问题描述】:

我有一个项目如下:

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

pom.xml 的 Project-B:

<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 em>。

我已经在 otherTests.java 中尝试过

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

但这似乎不起作用......

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

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

由于我不了解具体做了哪些更改,所以我不知道如何解决这个问题... 异常消息在 webapp-config.xml 中用作 &lt;context:property-placeholder location="classpath:exception-messages.properties" /&gt;

【问题讨论】:

    标签: spring junit spring-test spring-test-mvc


    【解决方案1】:

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

    编辑:

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

    【讨论】:

      猜你喜欢
      • 2013-10-29
      • 2011-10-30
      • 2010-11-16
      • 1970-01-01
      • 2019-12-10
      • 1970-01-01
      • 2012-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多