I have a simple Spock specification annotated with @SpringBootTest
and the class under test annotated with @Autowired
, but the test subject is null in the unit test. The controller is annotated with the @Controller
stereotype. Here's the test:
@SpringBootTest
class BeerControllerTest extends Specification {
@Autowired
BeerController testSubject
def "get beer by ID"() {
when:
def result = testSubject.getBeerById(UUID.randomUUID())
then:
result
println result
}
}
I have spock-core
and spock-spring
on the classpath (full code is here). In fact, the Spring Context is not even coming up when this test is run, which I have never seen in ~2 years of using Spock and Spring Boot. What am I missing here? It seems like a pretty simple use-case.