Closed andreygfranca closed 3 years ago
Hello.
Using @Shared
annotation solves the problem.
import spock.lang.Shared
class FooServiceSpec extends ITSpecification {
@Inject @Shared
FooService fooService
def "should return hello"() {
expect:
fooService.greet() == "hello"
}
}
Currently its designed so that @MicronautTest
must exist on each test class
I'm trying to create some integration tests on my project, and I have not just to insert some records on the database, but also get some container ports running with testcontainers lib (because ports are random when the application starts) before the test run. Usually, on spring projects I've been creating superclasses that do this kind of task (populating database, get random ports on runtime, etc.)
When using
@MicronautTest
annotation on a superclass and then inheriting this class on a concrete test class, beans are not being injected.Task List
Steps to Reproduce
FooService
)ITSpecification
that extends Specification (from spock framework)Error:
Expected Behaviour
Should allow injecting the beans into the base class because the superclass has the
@MicronautTest
annotationActual Behaviour
It is not allowing to inject beans into the base class
Environment Information