zoukankan      html  css  js  c++  java
  • spring框架和junit框架结合使用案例

     1 package ltssh;
     2 
     3 import org.junit.Test;
     4 import org.junit.runner.RunWith;
     5 import org.springframework.beans.factory.annotation.Autowired;
     6 import org.springframework.test.context.ContextConfiguration;
     7 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
     8 
     9 import com.lt.bean.Content;
    10 import com.lt.dao.content.IContentDao;
    11 
    12 /**
    13  * 
    14  * 类: JunitSpringTest <br>
    15  * 描述: spring框架和junit框架结合使用案例 <br>
    16  * 使用注解的方式读取配置文件,自动注入dao进行测试
    17  * 有点:干净整洁,代码优雅
    18  * 注意:@RunWith  @ContextConfiguration这两个注解的使用
    19  *         我是导入了最新版本的junit.jar和hamcrest-core-1.3.jar
    20  *         junit-4.4.jar版本的不支持
    21  */
    22 @RunWith(SpringJUnit4ClassRunner.class)
    23 @ContextConfiguration(locations={"classpath:applicationContext.xml"})
    24 public class JunitSpringTest {
    25 
    26     @Autowired
    27     private IContentDao contentDao;
    28     
    29     @Test
    30     public void handler(){
    31         Content content = contentDao.get(1);
    32         System.out.println(content.getTitle());
    33     }
    34 }

    package ltssh;

    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

    import com.lt.bean.Content;
    import com.lt.dao.content.IContentDao;

    /**
     *
     * 类: JunitSpringTest <br>
     * 描述: spring框架和junit框架结合使用案例 <br>
     * 使用注解的方式读取配置文件,自动注入dao进行测试
     * 有点:干净整洁,代码优雅
     * 注意:@RunWith  @ContextConfiguration这两个注解的使用
     *         我是导入了最新版本的junit.jar和hamcrest-core-1.3.jar
     *         junit-4.4.jar版本的不支持
     */
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations={"classpath:applicationContext.xml"})
    public class JunitSpringTest {

        @Autowired
        private IContentDao contentDao;
        
        @Test
        public void handler(){
            Content content = contentDao.get(1);
            System.out.println(content.getTitle());
        }
    }

  • 相关阅读:
    STM32F10x_ADC三通道逐次转换(单次、单通道软件触发)
    STM32F10x_RTC日历
    STM32F4_TIM输入波形捕获(脉冲频率)
    详解 C 语言开发五子棋游戏以及游戏中的重要算法与思路
    平安银行 深度解析梧州模式 或许是国内医药分开最好的模板!
    屏蔽双绞线和非屏蔽双绞线之间的区别
    如何刷新本地的DNS缓存?
    无线网络发射和接收的物理原理!
    wifi基本原理
    大润发创始人黄明端挥泪离场:我战胜了所有对手,却输给了时代!
  • 原文地址:https://www.cnblogs.com/sun-rain/p/5091541.html
Copyright © 2011-2022 走看看