zoukankan      html  css  js  c++  java
  • 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);
        }
    }

  • 相关阅读:
    Dice 5 ==> dice 7
    Dice 7 ==> dice 5
    100 floors 2 eggs
    Determine overlapping rectangles
    Product of integers
    Maximum profit of stocks
    样式表
    20170508
    2017年05月07
    The second day of school
  • 原文地址:https://www.cnblogs.com/Amywangqing/p/14828933.html
Copyright © 2011-2022 走看看