En mi caso, luego de luchar contra Lombok porque no funcionaba, este es mi codigo de test:
package com.med.voll.api.controller;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("test") // <--- Esto hace que busque application-test.properties
class ConsultaControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
@DisplayName("Deberia devolver http 400 cuando request esta vacia")
@WithMockUser
void reservar_escenario1() throws Exception {
var response = mockMvc.perform(post("/consultas"))
.andReturn().getResponse();
assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
}
}