Giriş
import org.springframework.test.context.ActiveProfile;Belirtilen profile ismine sahip bean'lerin yüklenmesini sağlar. Özellikle test kodlarında çok işe yarar.
Şöyle yaparız
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApplication.class, 
                webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class MyAwesomeFilterCustomPropertyIntegrationTest {
    @LocalServerPort
    private int port;
    @Autowired
    private TestRestTemplate restTemplate;
    @Test
    public void simpleRequestShouldUseMyAwesomeFilter() throws Exception {
        restTemplate.getForObject("http://localhost:" + port + "/",
                String.class);
    }
}src/test/resources/application-test.yml: 
Hiç yorum yok:
Yorum Gönder