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 @@ -5,11 +5,11 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.UniqueId;

public abstract class TestDataFactory {

Expand Down Expand Up @@ -46,29 +46,36 @@ private static <K, V> Map<K, V> addEntry(Map<K, V> originalMap, K key, V value)
}

public static TestIdentifier createTestIdentifier(TestDescriptor testDescriptor) {
UniqueId uniqueId = testDescriptor.getUniqueId();
return uniqueId
.getEngineId()
return engineId(testDescriptor)
.map(TEST_IDENTIFIER_FACTORY_BY_ENGINE_ID::get)
.orElse(JUnitPlatformUtils::toTestIdentifier)
.apply(testDescriptor);
}

public static TestSourceData createTestSourceData(TestDescriptor testDescriptor) {
UniqueId uniqueId = testDescriptor.getUniqueId();
return uniqueId
.getEngineId()
return engineId(testDescriptor)
.map(TEST_SOURCE_DATA_FACTORY_BY_ENGINE_ID::get)
.orElse(JUnitPlatformUtils::toTestSourceData)
.apply(testDescriptor);
}

public static boolean shouldBeTraced(TestDescriptor testDescriptor) {
UniqueId uniqueId = testDescriptor.getUniqueId();
return uniqueId
.getEngineId()
return engineId(testDescriptor)
.map(TEST_DESCRIPTOR_FILTER_BY_ENGINE_ID::get)
.map(filter -> filter.test(testDescriptor))
.orElse(true);
}

/**
* Resolves the innermost {@code engine} segment rather than the root one returned by the JUnit
* Platform {@code UniqueId#getEngineId()}.
*
* <p>Per-engine factories are registered under leaf engine ids ({@code cucumber}, {@code spock},
* ...). When a framework runs nested under {@code junit-platform-suite-engine}, the unique id is
* rooted at the suite engine (e.g. {@code
* [engine:junit-platform-suite]/[suite:...]/[engine:cucumber]/...}).
*/
private static Optional<String> engineId(TestDescriptor testDescriptor) {
return Optional.ofNullable(JUnitPlatformUtils.getEngineId(testDescriptor));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static void closeMockBackend() throws Exception {
"succeed-jacoco-argline | test_successful_maven_run_with_jacoco_and_argline | 3.9.9 | 5 | 1 | true | true | false | true | [] | 8 ",
"succeed-cucumber | test_successful_maven_run_with_cucumber | 3.9.9 | 4 | 1 | true | false | false | true | [] | 8 ",
"failed-flaky-retries | test_failed_maven_run_flaky_retries | 3.9.9 | 8 | 5 | false | false | true | true | [] | 8 ",
"cucumber-suite-flaky | test_maven_run_cucumber_suite_flaky_retries | 3.9.9 | 8 | 5 | false | false | true | false | [] | 17 ",
"succeed-junit-platform | test_successful_maven_run_junit_platform_runner | 3.9.9 | 4 | 0 | true | false | false | false | [] | 8 ",
"succeed-arg-line-property | test_successful_maven_run_with_arg_line_property | 3.9.9 | 4 | 0 | true | false | false | false | [\"-DargLine='-Dmy-custom-property=provided-via-command-line'\"] | 8 ",
"succeed-multi-forks-j8 | test_successful_maven_run_multiple_forks | 3.9.9 | 5 | 1 | true | true | false | true | [] | 8 ",
Expand Down Expand Up @@ -125,6 +126,10 @@ void testMavenRun(
"Maven Smoke Tests Project maven-surefire-plugin default-test",
"datadog.smoke.TestFailed",
"test_failed");
mockBackend.givenFlakyTest(
"Maven Smoke Tests Project maven-surefire-plugin default-test",
"classpath:datadog/smoke/basic_arithmetic.feature:Basic Arithmetic",
"Basic Arithmetic - Addition"); // cucumber.junit-platform.naming-strategy=long

mockBackend.givenTestsSkipping(testsSkipping);
mockBackend.givenSkippableTest(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[ {
"files" : [ {
"filename" : "src/test/resources/datadog/smoke/basic_arithmetic.feature"
}, {
"filename" : "src/test/java/datadog/smoke/calculator/CalculatorSteps.java"
} ],
"span_id" : ${content_parent_id},
"test_session_id" : ${content_test_session_id},
"test_suite_id" : ${content_test_suite_id}
}, {
"files" : [ {
"filename" : "src/test/resources/datadog/smoke/basic_arithmetic.feature"
}, {
"filename" : "src/test/java/datadog/smoke/calculator/CalculatorSteps.java"
} ],
"span_id" : ${content_parent_id_2},
"test_session_id" : ${content_test_session_id},
"test_suite_id" : ${content_test_suite_id}
}, {
"files" : [ {
"filename" : "src/test/resources/datadog/smoke/basic_arithmetic.feature"
}, {
"filename" : "src/test/java/datadog/smoke/calculator/CalculatorSteps.java"
} ],
"span_id" : ${content_parent_id_3},
"test_session_id" : ${content_test_session_id},
"test_suite_id" : ${content_test_suite_id}
}, {
"files" : [ {
"filename" : "src/test/resources/datadog/smoke/basic_arithmetic.feature"
}, {
"filename" : "src/test/java/datadog/smoke/calculator/CalculatorSteps.java"
} ],
"span_id" : ${content_parent_id_4},
"test_session_id" : ${content_test_session_id},
"test_suite_id" : ${content_test_suite_id}
}, {
"files" : [ {
"filename" : "src/test/resources/datadog/smoke/basic_arithmetic.feature"
}, {
"filename" : "src/test/java/datadog/smoke/calculator/CalculatorSteps.java"
} ],
"span_id" : ${content_parent_id_5},
"test_session_id" : ${content_test_session_id},
"test_suite_id" : ${content_test_suite_id}
} ]
Loading
Loading