Spring Boot 单元测试无法解决get

9rnv2umw  于 2023-01-20  发布在  Spring
关注(0)|答案(1)|浏览(170)

为什么inteli J不能解决get在我的单元测试?

package com.stev.pillecons.pilleCons;

import com.stev.pillecons.pilleCons.controllers.LePilleController;
import com.stev.pillecons.pilleCons.services.PilleService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

@RunWith(SpringRunner.class)
@WebMvcTest(LePilleController.class)
public class UnitTestPille {

    @Autowired
    private MockMvc mockMvc;

    @MockBean
    PilleService pilleService;

    @Test
    public void getAllPille() throws Exception {
         mockMvc.perform(get("/api/pille"))
                 .andExpect(status().isOk())
                 .andExpect(content())

    }
}

所有get()、status()和content()均为红色

pftdvrlh

pftdvrlh1#

您缺少静态导入:

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

相关问题