Fix test mongock#1
Open
dieppa wants to merge 4 commits into
Open
Conversation
This file contains hidden or 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
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.
Hello @pkubowicz .
Aplogies for the delay - I finally got the chance to take a look at your project. I forked it and did a PR with some suggested changes on how it is best practice to write the tests with Mongock.
During the analysis, I found out that you are loading the SpringContext - which already executes the Mongock migration - then you clean the data and execute Mongock again.
This is not the best approach for Mongock given the migration will already run during the loading time of the Spring Boot Application.
I'd suggest to do segregate the test cases:
This issue mainly covers the last one, testing the entire Spring boot application so that the Mongock runner again is not executed again.
To summarise: run the Spring boot application, with the Mongock process, ensuring some preconditions (in this case some pre-populated data in the database). This can be achieved in different ways, depending on the case, here you can create a InitializingBean like this:
and adding
@Import(InitializerContext.class):Then you can remove the MongockRunner and leave the test as simple as:
I hope this clarifies your case :)