-
Notifications
You must be signed in to change notification settings - Fork 314
Nikita tkachenko/junit6 integration #9509
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
Merged
nikita-tkachenko-datadog
merged 4 commits into
master
from
nikita-tkachenko/junit6-integration
Sep 11, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c61d138
Fix JUnit integration to work with JUnit 6
nikita-tkachenko-datadog 077a3c1
Bump dependencies
nikita-tkachenko-datadog ee3a11b
Add dedicated test fixtures for parameterized tests in JUnit 6 - sinc…
nikita-tkachenko-datadog 9cc5ae3
Add latest JUnit 5 test suite
nikita-tkachenko-datadog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
118 changes: 118 additions & 0 deletions
118
...junit-5.3/src/main/java/datadog/trace/instrumentation/junit5/ExecutionRequestFactory.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package datadog.trace.instrumentation.junit5; | ||
|
|
||
| import datadog.trace.util.MethodHandles; | ||
| import java.lang.invoke.MethodHandle; | ||
| import java.util.Arrays; | ||
| import java.util.function.BiFunction; | ||
| import org.junit.platform.commons.util.ClassLoaderUtils; | ||
| import org.junit.platform.engine.ConfigurationParameters; | ||
| import org.junit.platform.engine.EngineExecutionListener; | ||
| import org.junit.platform.engine.ExecutionRequest; | ||
| import org.junit.platform.engine.TestDescriptor; | ||
|
|
||
| public class ExecutionRequestFactory { | ||
|
|
||
| private static final MethodHandles METHOD_HANDLES = | ||
| new MethodHandles(ClassLoaderUtils.getDefaultClassLoader()); | ||
|
|
||
| /* | ||
| * From 5.13.0-RC1 onwards ExecutionRequest requires two additional arguments on creation. | ||
| * - OutputDirectoryProvider outputDirectoryProvider | ||
| * - NamespacedHierarchicalStore<Namespace> requestLevelStore | ||
| */ | ||
| private static final MethodHandle GET_OUTPUT_DIRECTORY_PROVIDER = | ||
| METHOD_HANDLES.method(ExecutionRequest.class, "getOutputDirectoryProvider"); | ||
| private static final MethodHandle GET_STORE = | ||
| METHOD_HANDLES.method(ExecutionRequest.class, "getStore"); | ||
| /* | ||
| * From 6.0.0-M2 onwards CancellationToken is also required. | ||
| */ | ||
| private static final MethodHandle GET_CANCELLATION_TOKEN = | ||
| METHOD_HANDLES.method(ExecutionRequest.class, "getCancellationToken"); | ||
|
|
||
| private static final String[] CREATE_PARAMETER_TYPES = | ||
| new String[] { | ||
| "org.junit.platform.engine.TestDescriptor", | ||
| "org.junit.platform.engine.EngineExecutionListener", | ||
| "org.junit.platform.engine.ConfigurationParameters", | ||
| "org.junit.platform.engine.reporting.OutputDirectoryProvider", | ||
| "org.junit.platform.engine.support.store.NamespacedHierarchicalStore", | ||
| "org.junit.platform.engine.CancellationToken" | ||
| }; | ||
|
|
||
| private static final BiFunction<ExecutionRequest, EngineExecutionListener, ExecutionRequest> | ||
| EXECUTION_REQUEST_CREATE = createExecutionRequestHandle(); | ||
|
|
||
| private static BiFunction<ExecutionRequest, EngineExecutionListener, ExecutionRequest> | ||
| createExecutionRequestHandle() { | ||
| // 6.0.0-M2 and later | ||
| if (GET_CANCELLATION_TOKEN != null) { | ||
| MethodHandle createMethod = | ||
| METHOD_HANDLES.method( | ||
| ExecutionRequest.class, | ||
| m -> | ||
| "create".equals(m.getName()) | ||
| && m.getParameterCount() == 6 | ||
| && Arrays.equals( | ||
| Arrays.stream(m.getParameterTypes()).map(Class::getName).toArray(), | ||
| CREATE_PARAMETER_TYPES)); | ||
|
|
||
| return (request, listener) -> { | ||
| Object provider = METHOD_HANDLES.invoke(GET_OUTPUT_DIRECTORY_PROVIDER, request); | ||
| Object store = METHOD_HANDLES.invoke(GET_STORE, request); | ||
| Object cancellationToken = METHOD_HANDLES.invoke(GET_CANCELLATION_TOKEN, request); | ||
| return METHOD_HANDLES.invoke( | ||
| createMethod, | ||
| request.getRootTestDescriptor(), | ||
| listener, | ||
| request.getConfigurationParameters(), | ||
| provider, | ||
| store, | ||
| cancellationToken); | ||
| }; | ||
| } | ||
|
|
||
| // 5.13.0-RC1 and later | ||
| if (GET_STORE != null && GET_OUTPUT_DIRECTORY_PROVIDER != null) { | ||
| MethodHandle createMethod = | ||
| METHOD_HANDLES.method( | ||
| ExecutionRequest.class, | ||
| m -> | ||
| "create".equals(m.getName()) | ||
| && m.getParameterCount() == 5 | ||
| && Arrays.equals( | ||
| Arrays.stream(m.getParameterTypes()).map(Class::getName).toArray(), | ||
| Arrays.copyOf(CREATE_PARAMETER_TYPES, 5))); | ||
|
|
||
| return (request, listener) -> { | ||
| Object provider = METHOD_HANDLES.invoke(GET_OUTPUT_DIRECTORY_PROVIDER, request); | ||
| Object store = METHOD_HANDLES.invoke(GET_STORE, request); | ||
| return METHOD_HANDLES.invoke( | ||
| createMethod, | ||
| request.getRootTestDescriptor(), | ||
| listener, | ||
| request.getConfigurationParameters(), | ||
| provider, | ||
| store); | ||
| }; | ||
| } | ||
|
|
||
| MethodHandle constructor = | ||
| METHOD_HANDLES.constructor( | ||
| ExecutionRequest.class, | ||
| TestDescriptor.class, | ||
| EngineExecutionListener.class, | ||
| ConfigurationParameters.class); | ||
| return (request, listener) -> | ||
| METHOD_HANDLES.invoke( | ||
| constructor, | ||
| request.getRootTestDescriptor(), | ||
| listener, | ||
| request.getConfigurationParameters()); | ||
| } | ||
|
|
||
| public static ExecutionRequest createExecutionRequest( | ||
| ExecutionRequest request, EngineExecutionListener listener) { | ||
| return EXECUTION_REQUEST_CREATE.apply(request, listener); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.