zoukankan      html  css  js  c++  java
  • dubbo+maven多模块项目单元测试

    基本上就是记录各种报错的解决办法。基本上就是将散落在项目各个模块中的配置文件复制到测试模块中。

    目录结构:

    ——src

        ——java

        ——test

          ——java

            ——DaoTest.java

          ——resources

            ——test

              ——applicationContext-dao.xml

              ——applicationContext-dubbo-client.xml

              ——applicationContext-dubbo-server.xml

              ——applicationContext-servcie.xml

              ——env.properties

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration({ "classpath:testing/applicationContext-*.xml" 
    "classpath:testing/example-config.xml",
    "classpath:testing/mq-receive.xml",
    "classpath:testing/mq-send.xml"})
    }) public class DaoTest { @Test public void test1(){ System.out.println("..."); } }

     datasource中加载配置文件:

    <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="testing/env.properties"/>
    </bean>

    比如错误:

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'XXX': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xxx.runtime.jms.send.xxxx com.xxxx.xxxx.service.common.ws.xxxx.xxxx; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.xxxx.runtime.jms.send.xxxx] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

    这基本就是该类所在的模块的配置文件没有引入到Junit中。

    最终因为业务太复杂,涉及到很多业务我根本不了解,所以我将单元测试放到了dao模块下,这样涉及到的无关模块最少,最后很容易的通过了单元测试

  • 相关阅读:
    ASP.NET中的状态保持(转载)
    Win7系统下VS2008安装SP1补丁解决JQuery无智能提示的问题
    合并多个List<T>类型并通过LINQ按指定属性排序
    ASP.NET状态保持:ViewState
    第一部分 CLR基础:第1章 CLR的执行模型
    Oracle存储过程知识汇总
    ASP.NET中Button控件的CommandName和CommandArgument属性用法
    PL/SQL Developer使用
    ASP.NET常用代码汇总
    PL/SQL Developer中文注释乱码的解决办法
  • 原文地址:https://www.cnblogs.com/guazi/p/7085272.html
Copyright © 2011-2022 走看看