Skip to content
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

Not all methods of Springs TestContextManager are invoked. #2572

Open
mpkorstanje opened this issue Jun 19, 2022 · 1 comment
Open

Not all methods of Springs TestContextManager are invoked. #2572

mpkorstanje opened this issue Jun 19, 2022 · 1 comment
Labels
πŸ› bug Defect / Bug ⚑ enhancement Request for new functionality
Milestone

Comments

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Jun 19, 2022

πŸ‘“ What did you see?

Not all methods of Springs TestContextManager are invoked.

βœ… What did you expect to see?

To facilitate integration testing frameworks such as Cucumber, Spring provides a TestContextManager to help setup a Spring application for tests. However currently not all methods are invoked, or invoked with partial information.

TestContextManager is the main entry point into the Spring TestContext Framework.
Specifically, a TestContextManager is responsible for managing a single TestContext and signaling events to each registered TestExecutionListener at the following test execution points.

  • before test class execution: prior to any before class callbacks of a particular testing framework (e.g., JUnit 4's @BeforeClass)
  • test instance preparation: immediately following instantiation of the test class
  • before test setup: prior to any before method callbacks of a particular testing framework (e.g., JUnit 4's @before)
  • before test execution: immediately before execution of the test method but after test setup
  • after test execution: immediately after execution of the test method but before test tear down
  • after test tear down: after any after method callbacks of a particular testing framework (e.g., JUnit 4's @after)
  • after test class execution: after any after class callbacks of a particular testing framework (e.g., JUnit 4's @afterclass)

Cucumber currently does not invoke test instance preparation, before test execution, after test execution at all. Cucumber can not invoke these methods with the correct semantics because the ObjectFactory is not aware of the test execution and can not execute anything between the execution of before scenario hooks and step definitions. Further more, the ObjectFactory is not aware of aware of the result of any scenario and can not pass any exceptions thrown to the after- methods.

πŸ›οΈ What would be a possible solution?

After #2174 it should be possible to refactor Cucumbers internals such that instead of providing providing Backend and ObjectFactory extension points, we can provide individual extension points equivalent to JUnit Jupiters: BeforeAllCallback, AfterAllCallback, TestInstancePostProcessor, BeforeEachCallback, AfterEachCallback, BeforeTestExecutionCallback and AfterTestExecutionCallback. To ensure these callbacks can transfer state an equivalent to JUnit Jupiters ExtensionContext would also have to be provided. Specifically the ObjectFactory could be replaced with the TestInstanceFactory and Backend could be reduced to only the discovery of glue definitions.

Additional benefits of closely following this pattern would be the relative ease by which we can re-implement existing extensions from JUnit JUpiter for Cucumber. We can benefit from a larger ecosystem here.

Do note: A 1-to-1 adoption of JUnit Jupiters extension system is not possible. JUnit Jupiter assumes that there is a single test class, test instance, and method. Cucumber generally has multiple.

@mpkorstanje mpkorstanje added the πŸ› bug Defect / Bug label Jun 19, 2022
@mpkorstanje mpkorstanje added this to the v8.0.0 milestone Jun 19, 2022
@mpkorstanje mpkorstanje added the ⚑ enhancement Request for new functionality label Jun 19, 2022
mpkorstanje added a commit that referenced this issue Dec 11, 2022
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 added a commit that referenced this issue Dec 11, 2022
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 added a commit that referenced this issue Dec 11, 2022
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 added a commit that referenced this issue Dec 11, 2022
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 added a commit that referenced this issue Dec 11, 2022
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
@stale
Copy link

stale bot commented Apr 15, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two months if no further activity occurs.

@stale stale bot added the βŒ› stale Will soon be closed by stalebot unless there is activity label Apr 15, 2023
@mpkorstanje mpkorstanje removed the βŒ› stale Will soon be closed by stalebot unless there is activity label Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
πŸ› bug Defect / Bug ⚑ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

1 participant