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

Move TogglzTestExecutionListener out of togglz-spring-core module #997

Open
hantsy opened this issue Apr 7, 2023 · 5 comments
Open

Move TogglzTestExecutionListener out of togglz-spring-core module #997

hantsy opened this issue Apr 7, 2023 · 5 comments

Comments

@hantsy
Copy link

hantsy commented Apr 7, 2023

When adding starter into the project, the TogglzTestExecutionListener will be enabled by default for tests, and it is better to move it standalone module(eg. togglz-spring-test) and allow developers to add it manually.

Additionally when I try to mock FeatureManager in my tests it always fails my mocks.

@hantsy hantsy changed the title Move TogglzTestExecutionListener out of togglz-spring module Move TogglzTestExecutionListener out of togglz-spring-core module Apr 12, 2023
@bennetelli
Copy link
Member

You actually don't have to mock it. Togglz ships with a special module for unit testing feature toggles: https://www.togglz.org/documentation/testing.html

@hantsy
Copy link
Author

hantsy commented Apr 17, 2023

I know well about this testing feature provided by togglze, but in our controller test, I would like to isolate any dependencies and focus on request/response verfication.

Unfortunately, we can not mock featureManager there due to the togglz TestExecutionListener.

@hantsy
Copy link
Author

hantsy commented Apr 17, 2023

And if I provide custom State Repository, User Repository, Activation Strategy implementations, and then the togglz testing harness becomes heavy, I do not want to hit database when testing controllers.

@hantsy
Copy link
Author

hantsy commented May 2, 2023

When added togglz spring boot stater and use FeatureManager(Spy or inject, I can not mock due to the listener) in tests, this listener will fail a lot of my tests.

I also created an issue on Spring framework to avoid the useless test listeners that affected my tests. spring-projects/spring-framework#30321

@sbrannen
Copy link

sbrannen commented Oct 8, 2023

As I mentioned in spring-projects/spring-framework#30321 (comment):

... in the Spring TestContext Framework we recommend that listeners and customizer factories "only do something when they're supposed to do something."

...

Whereas, TogglzTestExecutionListener (almost?) always modifies the internal state of a FeatureManager bean, if present in the ApplicationContext.

To best support users with varying use cases, TogglzTestExecutionListener should only modify the state of a bean in the ApplicationContext if the user requests that -- for example, via a Togglz-specific annotation on the test class.

Phrased differently, the mere presence of the TogglzTestExecutionListener in the classpath should not result in the state of a bean in the ApplicationContext being modified automatically without the user requesting that.

In light of that, perhaps the Togglz team would consider introducing a test annotation to control/trigger the behavior of the TogglzTestExecutionListener.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants