zoukankan      html  css  js  c++  java
  • Spring 集成Junit单元测试

    1、在pom增加junit和spring-test

    <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.11</version>
          <scope>test</scope>
    </dependency>
    
    <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-test</artifactId>
          <version>${org.springframework.version}</version>
    </dependency>
    

      

    2、创建BaseJunit4Test 类

    import org.junit.runner.RunWith;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    
    
    @RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试
    @ContextConfiguration(locations = {"classpath:applicationContext.xml"}) //加载配置文件
    public class BaseJunit4Test {
    }
    

     

    3、创建单元测试

    public class XXXMapperTest extends BaseJunit4Test {
    
        @Autowired
        private XXXMapper xxxMapper;
    
        @Test
        public void queryList() throws Exception {
          List<UserInfo> list = xxxMapper.queryList();
            Assert.assertTrue(list.size() > 0);
        }
    
    }
    

     以上是对Dao层访问数据的测试。 

     

  • 相关阅读:
    saltstack
    python一个命令开启http服务器
    常用服务安装部署
    位置1
    linux中python3安装和使用
    Linux基础系统优化
    Shell基本命令
    linux系统目录结构
    远程连接linux服务器
    VMware和Centos安装使用
  • 原文地址:https://www.cnblogs.com/linlf03/p/9982467.html
Copyright © 2011-2022 走看看