IDEA springboot项目test类报错:Cannot resolve symbol ‘SpringJUnit4ClassRunner‘
ps:idea打开之后,发现test类报错:Cannot resolve symbol ‘SpringJUnit4ClassRunner’,注解全部爆红.
test类部分截图:
import com.fasterxml.jackson.databind.ObjectMapper;
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.http.MediaType;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import tk.mybatis.springboot.BussnessApplication;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
//@SpringApplicationConfiguration(classes = BussnessApplication.class)
//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@SpringBootTest(classes = BussnessApplication.class,webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
//@WebAppConfiguration
public class test{
@Autowired
private UserMapper userMapper;
@Autowired
private WebApplicationContext context;
解决方法: