zoukankan      html  css  js  c++  java
  • junit测试spring相关配置

    喜欢用Junit进行单元测试的时候,会碰到spring的配置文件无法映射,这样的问题我也碰到过,后来找到了解决办法,就是在类头部要增加注解,因为用junit测试的时候,是没有容器的放置相关配置,所以测试的时候会报空值错误。配置如下:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = { "classpath:/applicationContext.xml" })
    @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class })
    public class ServiceAttachmentServiceImplTest {
    
        @Resource
        private IServiceAttachmentService serviceAttachmentService;
        @Test//测试SQL语句
        public void testSQL() {
            List<ServiceAttachment> atts = serviceAttachmentService
                    .getScrollData().getResultList();
            }

    之前一个朋友告诉我,这样配置后还是错误的,后来朋友告诉我,spring的配置文件如果用表达式的方式填充properties属性的话也是无效的,需直接把值写进入配置文件,这个问题我没试过,有碰到这种问题的朋友可以试试。

  • 相关阅读:
    Topic for paper reading
    Github
    APPIUM+Python+HTMLTestRunner(转)
    PyCharm 2016.3.2 汉化
    APPIUM 常用API(转)
    Python IDE PyCharm2016.3.2(转)
    APPIUM笔记
    将博客搬至CSDN
    碎碎念
    关于set或map的key使用自定义类型的问题
  • 原文地址:https://www.cnblogs.com/smashed/p/4693173.html
Copyright © 2011-2022 走看看