Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ private void testCaseExecutionStarted(final TestDescriptor testDescriptor) {
private void testMethodExecutionStarted(TestDescriptor testDescriptor, MethodSource testSource) {
TestDescriptor suiteDescriptor = SpockUtils.getSpecDescriptor(testDescriptor);
String displayName = testDescriptor.getDisplayName();
String testParameters = JUnitPlatformUtils.getParameters(testSource, displayName);
String testParameters =
JUnitPlatformUtils.getParameters(testDescriptor, testSource, displayName);
List<String> tags = JUnitPlatformUtils.getTags(testDescriptor);
TestSourceData testSourceData = SpockUtils.toTestSourceData(testDescriptor);

Expand Down Expand Up @@ -221,7 +222,8 @@ private void testMethodExecutionSkipped(
final TestDescriptor testDescriptor, final MethodSource methodSource, final String reason) {
TestDescriptor suiteDescriptor = SpockUtils.getSpecDescriptor(testDescriptor);
String displayName = testDescriptor.getDisplayName();
String testParameters = JUnitPlatformUtils.getParameters(methodSource, displayName);
String testParameters =
JUnitPlatformUtils.getParameters(testDescriptor, methodSource, displayName);
List<String> tags =
testDescriptor.getTags().stream().map(TestTag::getName).collect(Collectors.toList());
TestSourceData testSourceData = SpockUtils.toTestSourceData(testDescriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public static TestIdentifier toTestIdentifier(TestDescriptor testDescriptor) {
MethodSource methodSource = (MethodSource) testSource;
String testSuiteName = methodSource.getClassName();
String displayName = spockNode.getDisplayName();
String testParameters = JUnitPlatformUtils.getParameters(methodSource, displayName);
String testParameters =
JUnitPlatformUtils.getParameters(testDescriptor, methodSource, displayName);
return new TestIdentifier(testSuiteName, displayName, testParameters);

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ private static Method getTestMethod(MethodSource methodSource) {
}
}

public static String getParameters(MethodSource methodSource, String displayName) {
if (methodSource.getMethodParameterTypes() == null
|| methodSource.getMethodParameterTypes().isEmpty()) {
return null;
public static String getParameters(
TestDescriptor testDescriptor, MethodSource methodSource, String displayName) {
if (isDynamicTest(testDescriptor)
|| (methodSource.getMethodParameterTypes() != null
&& !methodSource.getMethodParameterTypes().isEmpty())) {
return "{\"metadata\":{\"test_name\":" + toJson(displayName) + "}}";
}
return "{\"metadata\":{\"test_name\":" + toJson(displayName) + "}}";
return null;
}

@Nullable
Expand All @@ -164,7 +166,7 @@ public static TestIdentifier toTestIdentifier(TestDescriptor testDescriptor) {
String testSuiteName = methodSource.getClassName();
String testName = methodSource.getMethodName();
String displayName = testDescriptor.getDisplayName();
String testParameters = getParameters(methodSource, displayName);
String testParameters = getParameters(testDescriptor, methodSource, displayName);
return new TestIdentifier(testSuiteName, testName, testParameters);

} else {
Expand Down Expand Up @@ -240,6 +242,12 @@ public static boolean isParameterizedTest(TestDescriptor testDescriptor) {
return "test-template".equals(lastSegment.getType());
}

public static boolean isDynamicTest(TestDescriptor testDescriptor) {
// retries add a "retry-attempt" segment at the end of the uniqueId, so the "dynamic-test"
// segment might not be found in position (segments.size() - 1)
return getIDSegmentValue(testDescriptor, "dynamic-test") != null;
}

public static boolean isRetry(TestDescriptor testDescriptor) {
return getIDSegmentValue(testDescriptor, RETRY_DESCRIPTOR_ID_SUFFIX) != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import datadog.trace.api.civisibility.config.TestSourceData;
import datadog.trace.api.civisibility.execution.TestExecutionHistory;
import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentTracer;
import datadog.trace.bootstrap.instrumentation.api.Tags;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.platform.engine.EngineExecutionListener;
Expand Down Expand Up @@ -119,7 +122,8 @@ private void testMethodExecutionStarted(TestDescriptor testDescriptor, MethodSou

String displayName = testDescriptor.getDisplayName();
String testName = testSource.getMethodName();
String testParameters = JUnitPlatformUtils.getParameters(testSource, displayName);
String testParameters =
JUnitPlatformUtils.getParameters(testDescriptor, testSource, displayName);
List<String> tags = JUnitPlatformUtils.getTags(testDescriptor);
TestSourceData testSourceData = JUnitPlatformUtils.toTestSourceData(testDescriptor);

Expand All @@ -136,6 +140,13 @@ private void testMethodExecutionStarted(TestDescriptor testDescriptor, MethodSou
testSourceData,
null,
TestEventsHandlerHolder.getExecutionHistory(testDescriptor));

if (JUnitPlatformUtils.isDynamicTest(testDescriptor)) {
AgentSpan span = AgentTracer.activeSpan();
if (span != null) {
span.setTag(Tags.TEST_JUNIT_IS_DYNAMIC, true);
}
}
}

private void testCaseExecutionFinished(
Expand Down Expand Up @@ -224,7 +235,8 @@ private void testMethodExecutionSkipped(

String displayName = testDescriptor.getDisplayName();
String testName = testSource.getMethodName();
String testParameters = JUnitPlatformUtils.getParameters(testSource, displayName);
String testParameters =
JUnitPlatformUtils.getParameters(testDescriptor, testSource, displayName);
List<String> tags =
testDescriptor.getTags().stream().map(TestTag::getName).collect(Collectors.toList());
TestSourceData testSourceData = JUnitPlatformUtils.toTestSourceData(testDescriptor);
Expand All @@ -242,5 +254,12 @@ private void testMethodExecutionSkipped(
testSourceData,
reason,
TestEventsHandlerHolder.getExecutionHistory(testDescriptor));

if (JUnitPlatformUtils.isDynamicTest(testDescriptor)) {
AgentSpan span = AgentTracer.activeSpan();
if (span != null) {
span.setTag(Tags.TEST_JUNIT_IS_DYNAMIC, true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@
"test.final_status" : "pass",
"test.framework" : "junit5",
"test.framework_version" : ${content_meta_test_framework_version},
"test.junit5.is_dynamic" : "true",
"test.module" : "junit-5.3",
"test.name" : "test_factory",
"test.parameters" : "{\"metadata\":{\"test_name\":\"dynamic_test_succeed\"}}",
"test.source.file" : "dummy_source_path",
"test.source.method" : "test_factory()Ljava/lang/Iterable;",
"test.status" : "pass",
Expand Down Expand Up @@ -166,8 +168,10 @@
"test.final_status" : "pass",
"test.framework" : "junit5",
"test.framework_version" : ${content_meta_test_framework_version},
"test.junit5.is_dynamic" : "true",
"test.module" : "junit-5.3",
"test.name" : "test_factory",
"test.parameters" : "{\"metadata\":{\"test_name\":\"dynamic_test_succeed\"}}",
"test.source.file" : "dummy_source_path",
"test.source.method" : "test_factory()Ljava/lang/Iterable;",
"test.status" : "pass",
Expand Down Expand Up @@ -196,4 +200,4 @@
},
"type" : "test",
"version" : 2
} ]
} ]
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@
"test.final_status" : "pass",
"test.framework" : "junit5",
"test.framework_version" : ${content_meta_test_framework_version},
"test.junit5.is_dynamic" : "true",
"test.module" : "junit-5.3",
"test.name" : "test_factory",
"test.parameters" : "{\"metadata\":{\"test_name\":\"dynamic_test_succeed\"}}",
"test.source.file" : "dummy_source_path",
"test.source.method" : "test_factory()Ljava/lang/Iterable;",
"test.status" : "pass",
Expand Down Expand Up @@ -169,8 +171,10 @@
"test.failure_suppressed" : "true",
"test.framework" : "junit5",
"test.framework_version" : ${content_meta_test_framework_version},
"test.junit5.is_dynamic" : "true",
"test.module" : "junit-5.3",
"test.name" : "test_factory",
"test.parameters" : "{\"metadata\":{\"test_name\":\"dynamic_test_failed\"}}",
"test.source.file" : "dummy_source_path",
"test.source.method" : "test_factory()Ljava/lang/Iterable;",
"test.status" : "fail",
Expand Down Expand Up @@ -220,9 +224,11 @@
"test.failure_suppressed" : "true",
"test.framework" : "junit5",
"test.framework_version" : ${content_meta_test_framework_version},
"test.junit5.is_dynamic" : "true",
"test.is_retry" : "true",
"test.module" : "junit-5.3",
"test.name" : "test_factory",
"test.parameters" : "{\"metadata\":{\"test_name\":\"dynamic_test_failed\"}}",
"test.retry_reason" : "auto_test_retry",
"test.source.file" : "dummy_source_path",
"test.source.method" : "test_factory()Ljava/lang/Iterable;",
Expand Down Expand Up @@ -273,9 +279,11 @@
"test.failure_suppressed" : "true",
"test.framework" : "junit5",
"test.framework_version" : ${content_meta_test_framework_version},
"test.junit5.is_dynamic" : "true",
"test.is_retry" : "true",
"test.module" : "junit-5.3",
"test.name" : "test_factory",
"test.parameters" : "{\"metadata\":{\"test_name\":\"dynamic_test_failed\"}}",
"test.retry_reason" : "auto_test_retry",
"test.source.file" : "dummy_source_path",
"test.source.method" : "test_factory()Ljava/lang/Iterable;",
Expand Down Expand Up @@ -326,9 +334,11 @@
"test.failure_suppressed" : "true",
"test.framework" : "junit5",
"test.framework_version" : ${content_meta_test_framework_version},
"test.junit5.is_dynamic" : "true",
"test.is_retry" : "true",
"test.module" : "junit-5.3",
"test.name" : "test_factory",
"test.parameters" : "{\"metadata\":{\"test_name\":\"dynamic_test_failed\"}}",
"test.retry_reason" : "auto_test_retry",
"test.source.file" : "dummy_source_path",
"test.source.method" : "test_factory()Ljava/lang/Iterable;",
Expand Down Expand Up @@ -380,9 +390,11 @@
"test.framework" : "junit5",
"test.framework_version" : ${content_meta_test_framework_version},
"test.has_failed_all_retries" : "true",
"test.junit5.is_dynamic" : "true",
"test.is_retry" : "true",
"test.module" : "junit-5.3",
"test.name" : "test_factory",
"test.parameters" : "{\"metadata\":{\"test_name\":\"dynamic_test_failed\"}}",
"test.retry_reason" : "auto_test_retry",
"test.source.file" : "dummy_source_path",
"test.source.method" : "test_factory()Ljava/lang/Iterable;",
Expand Down Expand Up @@ -412,4 +424,4 @@
},
"type" : "test",
"version" : 2
} ]
} ]
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class Tags {
public static final String TEST_IS_NEW = "test.is_new";
public static final String TEST_IS_RETRY = "test.is_retry";
public static final String TEST_RETRY_REASON = "test.retry_reason";
public static final String TEST_JUNIT_IS_DYNAMIC = "test.junit5.is_dynamic";
public static final String TEST_IS_MODIFIED = "test.is_modified";
public static final String TEST_HAS_FAILED_ALL_RETRIES = "test.has_failed_all_retries";
public static final String TEST_FAILURE_SUPPRESSED = "test.failure_suppressed";
Expand Down
Loading