Home > Back-end >  spring boot unit test can not resolve get
spring boot unit test can not resolve get

Time:01-18

why inteli J can not resolve get in my unit test ?

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())

    }
}

all get(),status(), and content() are Red enter image description here

CodePudding user response:

You are missing the static imports:

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;
  • Related