展开全部
springboot与Junit有整合的方式,你可以模拟http请求从你的测试类发送请求到Controller,就像https://www.youyanpai.com/2018/springboot-test-with-junit4.html中描述的一样。32313133353236313431303231363533e58685e5aeb931333431346465下面我列出部分代码:package com.youyanpai;
import org.junit.Assert;
import org.junit.Before;
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 org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;