public class ForkedJvmExtension
extends Object
implements InvocationInterceptor
JUnit 5 InvocationInterceptor backing the ForkedJvm annotation. When applied, the test method is skipped in the current JVM and re-run in a freshly forked JVM via ForkedJvmTestRunner, with any declared system properties and JVM args.
Recursion is avoided by setting the system property ForkedJvmTestRunner.FORKED_FLAG on the child; when the extension sees that flag set in the current JVM it just proceeds with the normal invocation (i.e. the child JVM actually runs the test body).
| Modifiers | Name | Description |
|---|---|---|
static String |
EXCLUDE_CLASSPATH_PROP |
System property naming a comma-separated list of regular expressions
to exclude from the parent's java.class.path when building
the forked JVM's classpath. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static String |
filterClasspath(String classpath, List<Pattern> excludes)Filters classpath (a File.pathSeparator-separated list)
by dropping entries that match any of the supplied regular expressions
via Matcher.find. |
|
public void |
interceptTestMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext)Runs the test body in this JVM when the forked-JVM flag is already set, or when neither the test method nor the test class carries ForkedJvm.
|
System property naming a comma-separated list of regular expressions
to exclude from the parent's java.class.path when building
the forked JVM's classpath. Augments
ForkedJvm.excludeFromClasspath.
Filters classpath (a File.pathSeparator-separated list)
by dropping entries that match any of the supplied regular expressions
via Matcher.find. Visible for testing.
classpath - the original classpath stringexcludes - regex patterns; an empty list returns classpath unchanged Runs the test body in this JVM when the forked-JVM flag is already set,
or when neither the test method nor the test class carries ForkedJvm.
Otherwise skips the invocation here and runs the same method in a child
process, then rethrows or aborts according to the child's result file.
invocation - the current test invocationinvocationContext - the method and target being interceptedextensionContext - the JUnit context used to find ForkedJvm