New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable default TestExecutionListeners in JUnit 4 and TestNG base test classes #29149
Comments
What happens if you use the following instead? @TestExecutionListeners(listeners = {}, inheritListeners = false, mergeMode = MergeMode.MERGE_WITH_DEFAULTS) That should allow you to switch to using all default listeners. |
Thanks for the reply. |
Hi @oopschen, Thanks for the feedback. For 6.0 we will remove the Since that may potentially be a breaking change for some users, we will only update the documentation for |
As spring test framework support testExecutionListener automatic discovery, when i build project using spring security with testng, it can not load META-INF/spring.factories file in org.springframework.security:spring-security-test library.(Same as Junit4, but works for junit5).
May affected spring version
since 4.1
After searching the source code of spring test framework, below is how it happened:
spring test framework testExecutionListener automatic discovery
Please check file org.springframework.test.context.support.AbstractTestContextBootstrapper at method getTestExecutionListeners.
The method prefer to load @TestExecutionListeners over META-INF/spring.factories , only if no @TestExecutionListeners annotation found, it loads default execution listeners(META-INF/spring.factories ).
IMPORTANT CODE FROM SPRING FRAMEWORK
As the code show, it must have testExecutionListeners.mergeMode() set to MergeMode.MERGE_WITH_DEFAULTS and either it has no super class or set testExecutionListeners.inheritListeners to false.
TestNG support
TestNG support spring test framework througth AbstractTestNGSpringContextTests and AbstractTransactionalTestNGSpringContextTests classes, both class annotated by @TestExecutionListeners annotation.
With the default value: inheritListeners set to true, mergeMode set to MergeMode.REPLACE_DEFAULTS
The Cause
Any class inherit AbstractTestNGSpringContextTests and AbstractTransactionalTestNGSpringContextTests will not load the default execution listeners(META-INF/spring.factories ). It will fail to take advantage of testExecutionListener automatic discovery mechanism, the same to Junit4.
Temporary solution
Annotate class inheriting AbstractTestNGSpringContextTests :
Solution Advice
The text was updated successfully, but these errors were encountered: