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

  • 相关阅读:
    [排序算法] 选择排序(2种)
    [排序算法] 交换排序(2种)
    针对Oracle表 列字段的增加、删除、修改以及重命名操作sql
    myelcipse中SVN进行代码更新和提交
    SVN服务器的搭建
    无法变更启动序列号
    mybatis入门学习记录(一)
    java中判断两个字符串是否相等的问题
    xshell如何同时打开多个标签
    设计模式(六) xml方式实现AOP
  • 原文地址:https://www.cnblogs.com/guazi/p/7085272.html
Copyright © 2011-2022 走看看