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

  • 相关阅读:
    XML HTML CSS JS的区别整理
    Python的作用域
    python文件操作总结
    python的open文件操作
    python使用struct处理二进制
    webstorm
    vue-cli项目中,配合element_ui来实现上传图片与视频到oss上。
    vue-cli项目中如何实现局部页面的刷新?
    基于cropper图片裁剪,兼容PC端与移动端
    跨域的完全讲解
  • 原文地址:https://www.cnblogs.com/guazi/p/7085272.html
Copyright © 2011-2022 走看看