-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Spring] Invoke all TestContextManager methods #2661
Merged
mpkorstanje
merged 1 commit into
main
from
spring-invoke-all-test-context-manager-phases
Dec 11, 2022
Merged
[Spring] Invoke all TestContextManager methods #2661
mpkorstanje
merged 1 commit into
main
from
spring-invoke-all-test-context-manager-phases
Dec 11, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
@@ Coverage Diff @@
## main #2661 +/- ##
============================================
+ Coverage 84.77% 84.81% +0.03%
- Complexity 2686 2693 +7
============================================
Files 322 322
Lines 9532 9570 +38
Branches 903 905 +2
============================================
+ Hits 8081 8117 +36
- Misses 1120 1121 +1
- Partials 331 332 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
mpkorstanje
force-pushed
the
spring-invoke-all-test-context-manager-phases
branch
from
December 11, 2022 15:38
74efc89
to
9370efa
Compare
mpkorstanje
changed the title
[Spring] Invoke all test context manager lifecycle phases
[Spring] Invoke all TestContextManager methods
Dec 11, 2022
mpkorstanje
force-pushed
the
spring-invoke-all-test-context-manager-phases
branch
2 times, most recently
from
December 11, 2022 15:43
6c1e4d6
to
6ee38e0
Compare
To make writing tests with Spring easier Spring provides a `TestContextManager`. This classes provides call backs for various `TestExecutionListeners`. These are then used by various extensions such as the `MockitoTestExecutionListener` which injects `@MockBeans` into test instances. When all methods are not invoked this leads to problems such as (#2654,#2655,#2656) While this was initially (#1470) not a problem, it appears that various listener implementations have started to assume that all methods would be invoked. Closes: #2655 Fixes: #2654, #2572
mpkorstanje
force-pushed
the
spring-invoke-all-test-context-manager-phases
branch
from
December 11, 2022 15:46
6ee38e0
to
aa55c97
Compare
mpkorstanje
deleted the
spring-invoke-all-test-context-manager-phases
branch
December 11, 2022 15:55
mpkorstanje
added a commit
that referenced
this pull request
Dec 16, 2022
… classes In #2661 classes annotated with `@CucumberContextConfiguration` were created as beans directly from the bean factory. This allowed them to be prepared as test instances by JUnit. However, we did not tell the factory that it should autowire constructor dependencies resulting in #2663. Additionally, because beans were created directly from the bean factory, they were not added to the application context. This meant that while dependencies could be injected into them, they could not be injected into other objects. Fixes: #2663
7 tasks
mpkorstanje
added a commit
that referenced
this pull request
Dec 16, 2022
In #2661 classes annotated with `@CucumberContextConfiguration` were created as beans directly from the bean factory. This allowed them to be prepared as test instances by JUnit. However, we did not tell the factory that it should autowire constructor dependencies resulting in #2663. Additionally, because beans were created directly from the bean factory, they were not added to the application context. This meant that while dependencies could be injected into them, they could not be injected into other objects. Fixes: #2663
mpkorstanje
added a commit
that referenced
this pull request
Dec 16, 2022
In #2661 classes annotated with `@CucumberContextConfiguration` were created as beans directly from the bean factory. This allowed them to be prepared as test instances by JUnit. However, we did not tell the factory that it should autowire constructor dependencies resulting in #2663. Additionally, because beans were created directly from the bean factory, they were not added to the application context. This meant that while dependencies could be injected into them, they could not be injected into other objects. Fixes: #2663
mpkorstanje
added a commit
that referenced
this pull request
Dec 16, 2022
…#2664) In #2661 classes annotated with `@CucumberContextConfiguration` were created as beans directly from the bean factory. This allowed them to be prepared as test instances by JUnit. However, we did not tell the factory that it should autowire constructor dependencies resulting in #2663. Additionally, because beans were created directly from the bean factory, they were not added to the application context. This meant that while dependencies could be injected into them, they could not be injected into other objects. Fixes: #2663
mpkorstanje
added a commit
that referenced
this pull request
May 24, 2024
Cucumber uses Spring Test Context Manager framework. This framework was written for JUnit and assumes that there is a "test instance". Cucumber however uses multiple step definition classes and so it has multiple test instances. Originally `@CucumberContextConfiguration` was added to signal to Spring which class should be used to configure the application context from. But as people also expected mock beans and other features provided by Springs test execution listeners to work (#2661) the annotated instance was only instantiated but never initialized by Spring. This changed the semantics somewhat as now features that depend on the bean being initialized stopped working (#2886). Unfortunately, there is little that can be done here. Spring expects that the instance provided to the Test Context Manager to be an uninitialized bean. The solution for this is to put the context configuration and step definitions in different classes. Cleaning up the examples to follow this pattern should avoid this problem somewhat in the future. Though I won't go as far as recommending people do this. Putting everything in one class looks quite nice. And generally still works. Closes: #2886
7 tasks
mpkorstanje
added a commit
that referenced
this pull request
May 24, 2024
Cucumber uses Spring Test Context Manager framework. This framework was written for JUnit and assumes that there is a "test instance". Cucumber however uses multiple step definition classes and so it has multiple test instances. Originally `@CucumberContextConfiguration` was added to signal to Spring which class should be used to configure the application context from. But as people also expected mock beans and other features provided by Springs test execution listeners to work (#2661) the annotated instance was only instantiated but never initialized by Spring. This changed the semantics somewhat as now features that depend on the bean being initialized stopped working (#2886). Unfortunately, there is little that can be done here. Spring expects that the instance provided to the Test Context Manager to be an uninitialized bean. The solution for this is to put the context configuration and step definitions in different classes. Cleaning up the examples to follow this pattern should avoid this problem somewhat in the future. Though I won't go as far as recommending people do this. Putting everything in one class looks quite nice. And generally still works. Closes: #2886
mpkorstanje
added a commit
that referenced
this pull request
Sep 12, 2024
Cucumber uses Spring Test Context Manager framework. This framework was written for JUnit and assumes that there is a "test instance". Cucumber however uses multiple step definition classes and so it has multiple test instances. Originally `@CucumberContextConfiguration` was added to signal to Spring which class should be used to configure the application context from. But as people also expected mock beans and other features provided by Springs test execution listeners to work (#2661) the annotated instance was only instantiated but never initialized by Spring. This changed the semantics somewhat as now features that depend on the bean being initialized stopped working (#2886). Unfortunately, there is little that can be done here. Spring expects that the instance provided to the Test Context Manager to be an uninitialized bean. The solution for this is to put the context configuration and step definitions in different classes. Cleaning up the examples to follow this pattern should avoid this problem somewhat in the future. Though I won't go as far as recommending people do this. Putting everything in one class looks quite nice. And generally still works. Closes: #2886
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
⚡️ What's your motivation?
To make writing tests with Spring easier Spring provides a
TestContextManager
. This classes provides call backs for variousTestExecutionListeners
.These are then used by various extensions such as
the
MockitoTestExecutionListener
which injects@MockBeans
into testinstances. When all methods are not invoked this leads to problems such as
(#2654,#2655,#2656)
While this was initially (#1470) not a problem, it appears that various
listener implementations have started to assume that all methods would be
invoked.
Closes: #2655
Fixes: #2654, #2572
🏷️ What kind of change is this?
📋 Checklist: