本文主要是记录在 Spring Boot 项目中如何简单使用单元测试
,对于相关的原理及知识暂不介绍。行文仓促,若有不妥之处,望各位大佬不吝赐教。
文章目录
一、搭建 Spring Boot 项目
这里展示部分代码,注意所用的数据库表(user
)含有 user_id、user_name
两个字段。
- UserController.java
package com.example.study.unitteststudy.controller;
import com.example.study.unitteststudy.domain.User;
import com.example.study.unitteststudy.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author yi
* @date 2021/9/13 19:54
*/
@RestController
public class UserController {
private final UserService userService;
@Autowired
public UserController