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模块下,这样涉及到的无关模块最少,最后很容易的通过了单元测试

  • 相关阅读:
    设计模式-抽象工厂模式
    装修预算-资料收集
    SQL中存储过程和函数的区别
    View
    数据表优化
    Entity Framework 基础
    html5标准
    JS整数验证
    vue 页面切换从右侧切入效果
    vue动态设置Iview的多个Input组件自动获取焦点
  • 原文地址:https://www.cnblogs.com/guazi/p/7085272.html
Copyright © 2011-2022 走看看