-
Notifications
You must be signed in to change notification settings - Fork 51
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
Junit5 support #94
Comments
We migrate to JUnit5 also, support would be nice |
As upgrading to JUnit 5 was a priority for us, we implemented a custom solution to overcome this issue. Unfortunately, because the impact of the solution affects more than just the GwtMockito test classes (and we removed all code that is not relevant for our project), it is not really suitable to create a PR for it. If any of the following is incorrect, or you see a better solution, feel free to correct me! This is what we came up with after some trial and error, it is possible that there is a better solution out there. The way GwtMockito works with JUnit 4, is replacing the test class itself with a custom loaded version of it (and setting a custom ClassLoader for the rest of the test). This can be seen in the GwtMockitoTestRunner implementation:
With JUnit 4, you could overwrite the default test Runner with the In our approach, we use a custom LauncherInterceptor. The problem with this is, that the ClassLoader gets applied to all test classes in the affected module. To mitigate this issue, we put all GwtMockito test classes into one module and only applied the changes to those. With this, you can more or less reuse the GwtMockito-Junit 4 code. All the new GwtMockitoExtension need to do is initializing the mocks. Something like this:
This allows us to run our GwtMockito tests with JUnit 5. The only thing we needed to change in the test themselves, was replacing the JUnit 4 Runners with the new GwtMockitoExtension. TL;DR: GwtMockito overwrites the ClassLoader in a custom Runner. JUnit 5 does not allow this, therefore a different way to overwrite the ClassLoader needs to be found. We used a custom LauncherInterceptor. |
Will there be support for juni5? So that the user can replace @RunWith(GwtMockitoTestRunner.class) with @ExtendWith(GwtMockitoExtension.class)
The text was updated successfully, but these errors were encountered: