This is a spock test using groovy
This is my code
@SpringBootTest
class SrMetricServiceAspectTest extends Specification {
@Autowired
@Qualifier("potentialSrCreation")
private SrCreationService service
@MockBean
SrMetricService srMetricService
@TestConfiguration
static class TestConfig {
@Bean("potentialSrCreation")
SrCreationService getSrCreationService() {
// Return an instance of PotentialSrCreation with necessary dependencies
return new PotentialSrCreation()
}
}
}
I have a groovy test in the structure of
def "..." () {
given:
...
when:
...
then:
...
However when I run the test, service itself is null. Is there an issue with my configuration/injection? I'm trying to define the bean within the test file.
In the groovy with spock tests you should use
@SpringBeanto create and inject mocks into application contextUsing @SpringBean