-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor tests #80
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
base: main
Are you sure you want to change the base?
Refactor tests #80
Conversation
| public abstract class AbstractSpringTest { | ||
|
|
||
| @TempDir | ||
| static protected Path tempDir; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main issue is with BasePersistenceFactory. Because it is annotated with @configuration, it gets initialised before we can create a temporary folder and set it as the source for BasePersistenceFactory.
The only reliable way we found to inject a temporary directory is via @DynamicPropertySource. However, this method requires the property to be static. As a result, the temporary directory also has to be static, which is counterintuitive when we want isolated temporary folders for each test.
One workaround is to set a static temporary folder as the initial source so that BasePersistenceFactory does not attempt to create its own directories, and then override this value in @beforeeach with a new temporary folder. This approach works, but in some tests it leads to desynchronization between the current working directory and the one registered earlier. While this can be solved by adjusting the affected tests, it makes the setup less intuitive and harder to maintain.
Overall, I have this solution coded and can push it, but I'm not sure if it would be worth it.
| import java.nio.file.Path; | ||
|
|
||
| @SpringBootTest | ||
| @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this ?
|
|
||
| @SpringBootTest | ||
| @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) | ||
| public abstract class AbstractSpringTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to extend every test with this ?
91a706c to
c5a4f80
Compare
c5a4f80 to
e023da4
Compare
|
In short, here’s the solution:
This cleanly separates repository handling logic between prod and test, while keeping the overall design consistent and minimally changed. Additionally:
|
Resolves #79