zoukankan      html  css  js  c++  java
  • Spring整合JUnit4测试

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = {"classpath:spring/applicationContext-dao.xml",
            "classpath:spring/applicationContext-service.xml","classpath:spring/applicationContext-trans.xml"})
    public class SpringJunitTest {
        //Spring运行器+Spring配置文件,我们就得到了Spring容器,容器拿到了,里面的东西(bean等)就拿到了
    }

    需要做单元测试时继承这个类

    public class TestTestTb extends SpringJunitTest {
    
        @Autowired
        private TestTbService testTbService;
    
        @Test
        public void testAdd() throws Exception{
            TestTb testTb = new TestTb();
            testTb.setName("zhangsan");
            testTbService.addTestTb(testTb);
    
        }
    }

    提高了扩展性

    注意,有多个配置文件时用{}

    @ContextConfiguration(locations = {"classpath:spring/applicationContext-dao.xml",
    "classpath:spring/applicationContext-service.xml","classpath:spring/applicationContext-trans.xml"})
  • 相关阅读:
    python的元类
    中国的互联网:草根与精英
    PEP8中文翻译
    一些重要的算法
    tornado模板语法
    C#l类与对象
    sql_ 存储过程
    SQL_触发器
    SQL_事务处理
    C#_方法
  • 原文地址:https://www.cnblogs.com/winner-0715/p/5534635.html
Copyright © 2011-2022 走看看