Search results
Replace Spring's @Value in Spring Boot Integration Tests
DefaultProvisioningService.java
:
@Service
@RequiredArgsConstructor
public class DefaultProvisioningService implements ProvisioningService {
@Value("${asimiotech.some-url}") // Configured in properties file
private String someUrl;
private final UserRepository userRepository;
// ...
}
Usage
- Spring Profile test properties file:
SalesReportControllerIntegrationTest.java
:
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class SalesReportControllerIntegrationTest {
// ...
}
and
src/test/resources/application-test.yml
:
asimiotech:
some-url: http://some-mocked-url.com
- @TestPropertySource
SalesReportControllerIntegrationTest.java
:
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = {
"asimiotech.some-url = http://some-mocked-url.com"
})
public class SalesReportControllerIntegrationTest {
// ...
}