• SpringBoot使用Junit


            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>

    一个项目中我们会写很多很多测试类,而测试类上面是需要以下几个注解的,每建一个类都去补注解,太麻烦,我们就在这个类中加上注解,其他测试类直接继承这个类就好了

    package com.qingfeng.weixi_pay;
    
    import org.junit.runner.RunWith;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    
    @SpringBootTest
    @RunWith(SpringRunner.class)
    public class WeixiPayApplicationTests {
    
    
    
    
    }
    package com.qingfeng.weixi_pay.controller;
    
    import com.qingfeng.weixi_pay.WeixiPayApplicationTests;
    import com.qingfeng.weixi_pay.mapper.UserInfoMapper;
    import com.qingfeng.weixi_pay.model.UserInfo;
    import org.junit.Test;
    import org.springframework.beans.factory.annotation.Autowired;
    
    public class TestControllerTest extends WeixiPayApplicationTests {
    
        @Autowired
        private UserInfoMapper userInfoMapper;
    
        @Test
        public void findAll() {
            UserInfo userInfo = userInfoMapper.selectById(1);
            System.out.println(userInfo);
        }
    }

  • 相关阅读:
    设置网页内容不准复制
    a标签打电话
    <base target="_blank" />
    常用sql语句 DML语句
    常用sql-----DDL语句
    php文件操作
    php格式化时间
    php 数组函数
    程序员和特种兵 几分相似几分无奈
    女码农的真实生活:程序“媛”无法卖萌
  • 原文地址:https://www.cnblogs.com/Amywangqing/p/14828933.html
Copyright © 2020-2023  润新知