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

Provide a JUnit 5 equivalent of ModifiedClassPathRunner #17491

Closed

Conversation

dreis2211
Copy link
Contributor

@dreis2211 dreis2211 commented Jul 11, 2019

Hi,

the last two days I worked on an alternative for the ModifiedClassPathRunner in order to complete the migration to JUnit 5 and workaround the missing classloader support described in #16957 and junit-team/junit5#201.

I've implemented an ModifiedClassPathExtension that works similar to the old ModifiedClassPathRunner and extracted the functionality that is shared between both. I did this because I deprecated ModifiedClassPathRunner instead of directly removing it, but I have no strong feelings for keeping the old stuff personally.

The new extension makes use of JUnit 5's Launcher API and executes the tests with the modified classloader while swallowing the original test results. Yet, it still executes the original tests due to the fact that JUnit 5 unfortunately requires the underlying Invocation to be processed. This leads obviously to slightly higher test execution times and makes proper test setup and cleaning (e.g. through @BeforeAll and @AfterAll) more important, but I found this to be reasonable still.

With the new extension I was able to move all tests to JUnit 5. The extension is obviously not perfect and is a workaround until native classloader support in JUnit 5 arrives, but having no JUnit 4 tests anymore is hopefully a convincing argument for this PR.

Let me know what you think.
Cheers,
Christoph

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 11, 2019
@dreis2211
Copy link
Contributor Author

dreis2211 commented Jul 11, 2019

There is a test failing that doesn't seem to have anything to do with my changes as it's not using the new extension. Seems unrelated to my changes but changes in spring-projects/spring-data-relational@b7ee1bb. I might be wrong.

@wilkinsona
Copy link
Member

Thanks very much for taking a look at this, @dreis2211. While we certainly dislike having a mixture of JUnit 4 and JUnit 5-based tests, I'm afraid we dislike the tests being run twice a little bit more. We're concerned that it'll cause confusion in the future as log output will be generated twice and debugging will be harder as well due to everything being invoked twice.

That said, there's a lot of great stuff here even without the move to the new extension. Would you be interested in splitting this into two? We'd quite like to merge the introduction of the ModifiedClassPathLoaderFactory now and leave the move to a new ModifiedClassPathExtension till JUnit has the necessary extension point available.

@dreis2211
Copy link
Contributor Author

@wilkinsona That's unfortunate, but understandable. I have one more thing I'd like to try out in order to avoid the duplicated execution. Would this change your mind if that works?

@dreis2211
Copy link
Contributor Author

dreis2211 commented Jul 11, 2019

@wilkinsona I indeed found a way to avoid the duplicated test execution. Hope that changes your mind about the PR :)

@wilkinsona wilkinsona added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 12, 2019
@wilkinsona wilkinsona added this to the 2.2.x milestone Jul 12, 2019
@philwebb philwebb self-assigned this Jul 14, 2019
philwebb pushed a commit that referenced this pull request Jul 14, 2019
Migrate a new tests to use the `ApplicationContextRunner`.

See gh-17491
philwebb pushed a commit that referenced this pull request Jul 14, 2019
philwebb pushed a commit that referenced this pull request Jul 14, 2019
Migrate `RestClientTestWithoutJacksonIntegrationTests` to use
Spring's `MockRestServiceServer`.

See gh-17491
philwebb pushed a commit that referenced this pull request Jul 14, 2019
Extract classes from `ModifiedClassPathRunner` so that they can
be reused.

See gh-17491
philwebb pushed a commit that referenced this pull request Jul 14, 2019
Add a JUnit 5 extension that allows tests to be run with a
modified classpath. Since JUnit 5 does not currently offer a way
to run tests with a different classpath, we instead fake the
original invocation and launch an entirely new run for each
method.

See gh-17491
philwebb pushed a commit that referenced this pull request Jul 14, 2019
Migrate the remaining JUnit 4 tests to JUnit 5, making use of the
new `ModifiedClassPathExtension`.

See gh-17491
philwebb added a commit that referenced this pull request Jul 14, 2019
philwebb added a commit that referenced this pull request Jul 14, 2019
Delete `ModifiedClassPathRunner` since we no longer have any tests
that use it.

See gh-17491
@philwebb philwebb closed this in 4b744bd Jul 14, 2019
@philwebb
Copy link
Member

@dreis2211 This was an absolute monster effort!! Thanks so much. It's now been merged to master but I've chopped the PR up into a number of smaller commits. The reflection calls are a little brittle, but hopefully those JUnit internals won't change too much.

Thanks again!

@wilkinsona wilkinsona modified the milestones: 2.2.x, 2.2.0.M5 Jul 15, 2019
philwebb added a commit that referenced this pull request Jul 15, 2019
Remove the `ModifiedClassPathClassLoaderFactory` in favor of
factory methods on `ModifiedClassPathClassLoader`.

See gh-17491
philwebb added a commit that referenced this pull request Jul 15, 2019
Meta-annotate `ClassPathExclusions` and `ClassPathOverrides` with
so that the `ModifiedClassPathExtension` no longer needs to be
used directly.

See gh-17491
philwebb added a commit that referenced this pull request Jul 15, 2019
Remove `runner` since we're no longer tied to JUnit 4.

See gh-17491
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants