首页 > 编程语言 > 详细

SpringBoot写测试类

时间:2020-03-25 15:46:34      阅读:46      评论:0      收藏:0      [点我收藏+]

导包

<!--测试-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>

  光标在类名上,快捷键Alt+Enter 

 技术分享图片

 

 技术分享图片

 

 

package com.company.mapper;

import com.company.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import static org.junit.jupiter.api.Assertions.*;

//加上这两个注解,运行测试方法的时候就会启动SpringBoot
@RunWith(SpringRunner.class)
@SpringBootTest
public class UserMapperTest {
@Autowired
private UserMapper mapper;

@Test
public void testUser(){
System.out.println(mapper.selectByPrimaryKey(1));
}
}

SpringBoot写测试类

原文:https://www.cnblogs.com/zou-rong/p/12566197.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!