• Spring的测试


    spring测试要引用junit及spring-test

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

    代码:

    配置文件的引入:

    单个文件:@ContextConfiguration(locations ="classpath:spring-mybatis.xml")

    多个文件:@ContextConfiguration(locations ={"classpath:spring-mybatis.xml","classpath:application-context-provider.xml"})

    import com.zoe.aop.dto.*;
    import com.zoe.aop.service.out.DeptService;
    import org.junit.Assert;
    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;
    
    /**
     * Created by gyoung on 2016/1/23.
     */
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations ={"classpath:spring-mybatis.xml","classpath:application-context-provider.xml"})
    public class DeptServerTest {
    
        @Autowired
        private DeptService deptService;
    
        @Test
        public void deptSelectTest() {
            DeptDto model= deptService.getOneById("2");
            Assert.assertTrue(model.getId().equals("2"));
        }
    
        @Test
        public void updateTest(){
            DeptDto model= new DeptDto();
            model.setId("2");
            model.setName("111");
            deptService.update(model);
            String id=model.getId();
        }
    
        @Test
        public void pageTest(){
            QueryPage page=new QueryPage(1,5);
            ServiceResultT<CorePageList> resultT= deptService.getList(page);
        }
    
        @Test
        public void deleteTtest(){
            ServiceResult result= deptService.deleteById("1203");
        }
    
        @Test
        public void updateDbTest(){
    
        }
    }
  • 相关阅读:
    sql处理数据库锁的存储过程
    SQL语句
    partial 函数
    map函数
    python命令行上下 退格,左右键不能用
    postgresql 在linux上的源码安装
    python字典操作
    根据key存不存在查询json
    精典博文
    python解析XML之ElementTree
  • 原文地址:https://www.cnblogs.com/Gyoung/p/5197397.html
Copyright © 2020-2023  润新知