You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have my own extension for helping with cross cutting concerns in Micronaut tests and I use the ExtensionContext to get the ApplicationContext. I think this is causing issues for me when I run with rebuildContext = true
See attached reproducing application
The expected behavior is that the ApplicationContext in the extension and the ApplicationContext injected in the test should be the same for each test method
Actual Behaviour
When running the attached application, you can see the ApplicationContext injected into the test differs each time
But the ApplicationContext known by the extension is not updated:
09:46:13.385 [main] INFO i.m.context.env.DefaultEnvironment - Established active environments: [test]
09:46:13.964 [main] ERROR com.example.MyJUnit5Extension - ApplicationContext = io.micronaut.context.DefaultApplicationContext@4e9658b5
09:46:13.973 [main] ERROR com.example.DemoTest - ApplicationContext = io.micronaut.context.DefaultApplicationContext@4e9658b5
09:46:14.048 [main] INFO i.m.context.env.DefaultEnvironment - Established active environments: [test]
09:46:14.102 [main] ERROR com.example.MyJUnit5Extension - ApplicationContext = io.micronaut.context.DefaultApplicationContext@4e9658b5
09:46:14.103 [main] ERROR com.example.DemoTest - ApplicationContext = io.micronaut.context.DefaultApplicationContext@65ef722a
09:46:14.141 [main] INFO i.m.context.env.DefaultEnvironment - Established active environments: [test]
09:46:14.194 [main] ERROR com.example.MyJUnit5Extension - ApplicationContext = io.micronaut.context.DefaultApplicationContext@4e9658b5
09:46:14.195 [main] ERROR com.example.DemoTest - ApplicationContext = io.micronaut.context.DefaultApplicationContext@251ebf23
...
Steps To Reproduce
Run mvn clean test using the attached example application
I was able to hack my way around this but I do not know how best to do it cleanly. The ApplicationContext is recreated by AbstractMicronautExtension which does not know about the JUnit ExtensionContext and there is no easy way to call back to MicronautJunit5Extension
EDIT: I guess maybe the naive way is maybe the best way; simply call store.put(ApplicationContext.class, applicationContext); inside MicronautJunit5Extension.beforeEach every time
Expected Behavior
In MicronautJunit5Extension, the
beforeAll
method puts theApplicationContext
into the JUnitExtensionContext
(https://github.com/micronaut-projects/micronaut-test/blob/v3.9.2/test-junit5/src/main/java/io/micronaut/test/extensions/junit5/MicronautJunit5Extension.java#L85)When
rebuildContext = true
, then theApplicationContext
is re-assigned to a new pointer (https://github.com/micronaut-projects/micronaut-test/blob/v3.9.2/test-core/src/main/java/io/micronaut/test/extensions/AbstractMicronautExtension.java#L361-L366) but the old pointer is still retained byExtensionContext
I have my own extension for helping with cross cutting concerns in Micronaut tests and I use the
ExtensionContext
to get theApplicationContext
. I think this is causing issues for me when I run withrebuildContext = true
See attached reproducing application
The expected behavior is that the
ApplicationContext
in the extension and theApplicationContext
injected in the test should be the same for each test methodActual Behaviour
When running the attached application, you can see the
ApplicationContext
injected into the test differs each timeBut the
ApplicationContext
known by the extension is not updated:Steps To Reproduce
Run
mvn clean test
using the attached example applicationdemo.zip
I was able to hack my way around this but I do not know how best to do it cleanly. The
ApplicationContext
is recreated byAbstractMicronautExtension
which does not know about the JUnitExtensionContext
and there is no easy way to call back toMicronautJunit5Extension
EDIT: I guess maybe the naive way is maybe the best way; simply call
store.put(ApplicationContext.class, applicationContext);
insideMicronautJunit5Extension.beforeEach
every timeEnvironment Information
JDK 17
Micronaut 3.9.0
Linux
Example Application
https://github.com/micronaut-projects/micronaut-test/files/11355728/demo.zip
Version
3.9.0
The text was updated successfully, but these errors were encountered: