Skip to content

Separate ClassLoader per test #4203

Closed Answered by marcphilipp
WolfgangHG asked this question in Q&A
Discussion options

You must be logged in to vote

I created a sample based on a ServiceLoader-registered LauncherSessionListener here: https://github.com/marcphilipp/gradle-sandbox/tree/master/classloader-per-test-class

It installs a custom classloader for the entire session that then checks if a custom class loader is needed for each test class:
https://github.com/marcphilipp/gradle-sandbox/blob/baaa1972e939f5817f54a3d287611cef0601a58d/classloader-per-test-class/src/test/java/org/example/ClassLoaderReplacingLauncherSessionListener.java#L23-L44

For the detection I used a custom @SeparateClassLoader annotation that specifies a factory for creating the class loader. In the sample, a URLClassLoader is created that (to mimick your use case) …

Replies: 6 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by WolfgangHG
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@WolfgangHG
Comment options

@marcphilipp
Comment options

Comment options

You must be logged in to vote
3 replies
@marcphilipp
Comment options

@WolfgangHG
Comment options

@marcphilipp
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants