Closed snowdrop-bot closed 3 years ago
Mock injection is not performed before execution of unit tests inside nested test classes.
Attributes of the top level class annotated with @InjectMock are injected before the tests of @Nested test classes are executed.
@InjectMock
@Nested
Attributes annotated with @InjectMock are null.
null
A test like this fails because the service is not injected:
service
@QuarkusTest class TestClass { @InjectMock private MyService service; @Nested class NestedTest { @Test void myTest() { assertNotNull(service); } } }
And it passes if the nested class wrapper is removed.
uname -a
ver
2.1.0.Final
java -version
11
No response
mvnw --version
gradlew --version
Maven
https://github.com/quarkusio/quarkus/issues/19391
$upstream:19391$
Describe the bug
Mock injection is not performed before execution of unit tests inside nested test classes.
Expected behavior
Attributes of the top level class annotated with
@InjectMock
are injected before the tests of@Nested
test classes are executed.Actual behavior
Attributes annotated with
@InjectMock
arenull
.How to Reproduce?
A test like this fails because the
service
is not injected:And it passes if the nested class wrapper is removed.
Output of
uname -a
orver
2.1.0.Final
Output of
java -version
11
GraalVM version (if different from Java)
No response
Quarkus version or git rev
No response
Build tool (ie. output of
mvnw --version
orgradlew --version
)Maven
Additional information
No response
https://github.com/quarkusio/quarkus/issues/19391
$upstream:19391$