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

Testing: Cleanup Test resets #271

Closed
kmanning opened this issue Jul 31, 2020 · 4 comments · Fixed by #334
Closed

Testing: Cleanup Test resets #271

kmanning opened this issue Jul 31, 2020 · 4 comments · Fixed by #334
Labels
enhancement New feature or request testing Improve the test suite(s)
Milestone

Comments

@kmanning
Copy link
Collaborator

kmanning commented Jul 31, 2020

  • This library unfortunately has a lot of static state
  • You'll find a number of classes that have a reset() method, so that as we run unit tests, state modifications from one test don't unintentionally impact another test
  • This is really error prone, is difficult to detect when missed, and is just difficult to maintain. This feels like an anti-pattern.
  • Find a better solution for this.
  • Part of the solution is likely implementing a JUnitRule instead of @Before/@after reset() methods
@kmanning kmanning added this to the v6.0 milestone Jul 31, 2020
@kmanning kmanning added the enhancement New feature or request label Jul 31, 2020
@kmanning
Copy link
Collaborator Author

What if each class could register itself as "resettable". Then the rule would automatically iterate across every resettable object, between each test case. Then all a Dev would need to do is call the single JUnitRule, and not worry about the details of what's being reset.

@jantman
Copy link
Contributor

jantman commented Dec 10, 2020

Is there any way to have JUnit/Gradle run each test in a separate process? Is that a thing? When I've come across issues like this in other languages, either with static state or with import-time issues in dynamic languages, I've solved it by using a test runner that has the option of running each test in a completely new process/interpreter...

@kmanning kmanning modified the milestones: v6.0, v5.14 Jan 8, 2021
@kmanning kmanning changed the title Cleanup Test resets Testing: Cleanup Test resets Jan 22, 2021
@kmanning kmanning added the testing Improve the test suite(s) label Jan 22, 2021
@kmanning kmanning modified the milestones: v5.14, v5.15 Feb 1, 2021
@kmanning
Copy link
Collaborator Author

kmanning commented Feb 5, 2021

JUnit 5 has replaced @Rule with @Extension - https://junit.org/junit5/docs/current/user-guide/#extensions
Now that Issue #332 is resolved, the we've upgraded to Junit 5, create an Extension to reset any global state consistently between tests.

@kmanning
Copy link
Collaborator Author

kmanning commented Feb 9, 2021

Solution:

  1. Any class that has static state should implement Resettable, and add a reset() method that restores static state
  2. Any Test that modifies static state should use the ResetStaticStateExtension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request testing Improve the test suite(s)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants