Skip to content

Commit 202e7f7

Browse files
committed
Apply automation exclusions to Karate scenarios in both major versions
1 parent 1bf4e92 commit 202e7f7

9 files changed

Lines changed: 105 additions & 2 deletions

File tree

‎dd-java-agent/instrumentation/karate/karate-1.0/src/main/java/datadog/trace/instrumentation/karate/KarateTracingHook.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ public boolean beforeScenario(ScenarioRuntime sr) {
115115
if (Config.get().isCiVisibilityTestSkippingEnabled()
116116
|| Config.get().isCiVisibilityTestManagementEnabled()) {
117117
TestIdentifier skippableTest = KarateUtils.toTestIdentifier(scenario);
118-
SkipReason skipReason = TestEventsHandlerHolder.TEST_EVENTS_HANDLER.skipReason(skippableTest);
118+
SkipReason skipReason =
119+
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.skipReason(
120+
skippableTest, TestSourceData.UNKNOWN, categories);
119121

120122
if (skipReason != null
121123
&& !(skipReason == SkipReason.ITR

‎dd-java-agent/instrumentation/karate/karate-1.0/src/test/groovy/KarateTest.groovy‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,33 @@ import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass
2727
@DisableTestTrace(reason = "avoid self-tracing")
2828
class KarateTest extends CiVisibilityInstrumentationTest {
2929

30+
def "test automation exclusions preserve a blocking failure and execute once"() {
31+
given:
32+
def id = new TestFQN("[org/example/test_automation_excluded] automation exclusions", "protected_failure")
33+
givenDisabledTests([id])
34+
givenQuarantinedTests([id])
35+
givenAttemptToFixTests([id])
36+
givenFlakyRetryEnabled(true)
37+
givenFlakyTests([id])
38+
givenEarlyFlakinessDetectionEnabled(true)
39+
givenKnownTests([])
40+
41+
when:
42+
runTests([TestAutomationExcludedKarate], false)
43+
44+
then:
45+
TEST_WRITER.toList().flatten().count { it.getTag("test.name") == "protected_failure" } == 1
46+
def testSpan = TEST_WRITER.toList().flatten().find { it.getTag("test.name") == "protected_failure" }
47+
testSpan != null
48+
testSpan.getTag("test.test_management.no_auto_retry") == true
49+
testSpan.getTag("test.test_management.prevent_failure_suppression") == true
50+
testSpan.getTag("test.test_management.is_test_disabled") == true
51+
testSpan.getTag("test.test_management.is_quarantined") == true
52+
testSpan.getTag("test.test_management.is_attempt_to_fix") == true
53+
testSpan.getTag("test.test_management.attempt_to_fix_passed") == null
54+
}
55+
56+
3057
def "test #testcaseName"() {
3158
Assumptions.assumeTrue(assumption)
3259

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.example;
2+
3+
import com.intuit.karate.junit5.Karate;
4+
5+
public class TestAutomationExcludedKarate {
6+
7+
@Karate.Test
8+
public Karate testFailed() {
9+
return Karate.run("classpath:org/example/test_automation_excluded.feature");
10+
}
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Feature: automation exclusions
2+
3+
@datadog_no_auto_retry @datadog_prevent_failure_suppression
4+
Scenario: protected_failure
5+
* assert false

‎dd-java-agent/instrumentation/karate/karate-2.0/src/main/java21/datadog/trace/instrumentation/karate2/KarateTracingListener.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ private boolean beforeScenario(ScenarioRunEvent event) {
124124
if (Config.get().isCiVisibilityTestSkippingEnabled()
125125
|| Config.get().isCiVisibilityTestManagementEnabled()) {
126126
TestIdentifier skippableTest = KarateUtils.toTestIdentifier(scenario);
127-
SkipReason skipReason = TestEventsHandlerHolder.TEST_EVENTS_HANDLER.skipReason(skippableTest);
127+
SkipReason skipReason =
128+
TestEventsHandlerHolder.TEST_EVENTS_HANDLER.skipReason(
129+
skippableTest, TestSourceData.UNKNOWN, categories);
128130

129131
if (skipReason != null
130132
&& !(skipReason == SkipReason.ITR

‎dd-java-agent/instrumentation/karate/karate-2.0/src/test/groovy/KarateV2Test.groovy‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,33 @@ import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass
2121
@DisableTestTrace(reason = "avoid self-tracing")
2222
class KarateV2Test extends CiVisibilityInstrumentationTest {
2323

24+
def "test automation exclusions preserve a blocking failure and execute once"() {
25+
given:
26+
def id = new TestFQN("[org/example/test_automation_excluded] automation exclusions", "protected_failure")
27+
givenDisabledTests([id])
28+
givenQuarantinedTests([id])
29+
givenAttemptToFixTests([id])
30+
givenFlakyRetryEnabled(true)
31+
givenFlakyTests([id])
32+
givenEarlyFlakinessDetectionEnabled(true)
33+
givenKnownTests([])
34+
35+
when:
36+
runTests([TestAutomationExcludedKarate], false)
37+
38+
then:
39+
TEST_WRITER.toList().flatten().count { it.getTag("test.name") == "protected_failure" } == 1
40+
def testSpan = TEST_WRITER.toList().flatten().find { it.getTag("test.name") == "protected_failure" }
41+
testSpan != null
42+
testSpan.getTag("test.test_management.no_auto_retry") == true
43+
testSpan.getTag("test.test_management.prevent_failure_suppression") == true
44+
testSpan.getTag("test.test_management.is_test_disabled") == true
45+
testSpan.getTag("test.test_management.is_quarantined") == true
46+
testSpan.getTag("test.test_management.is_attempt_to_fix") == true
47+
testSpan.getTag("test.test_management.attempt_to_fix_passed") == null
48+
}
49+
50+
2451
def "test #testcaseName"() {
2552
runTests(tests, success)
2653

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.example;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import com.intuit.karate.Results;
6+
import com.intuit.karate.Runner;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class TestAutomationExcludedKarate {
10+
11+
@Test
12+
public void test() {
13+
Results results =
14+
Runner.path("classpath:org/example/test_automation_excluded.feature").parallel(1);
15+
assertEquals(0, results.getFailCount(), results.getErrorMessages());
16+
}
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Feature: automation exclusions
2+
3+
@datadog_no_auto_retry @datadog_prevent_failure_suppression
4+
Scenario: protected_failure
5+
* assert false

‎docs/test-automation-exclusions.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,10 @@ For either the JUnit4 or JUnit Platform Cucumber runner, tag a Scenario or
5454
Scenario Outline with `@datadog_no_auto_retry` and/or
5555
`@datadog_prevent_failure_suppression`. These names correspond to the public
5656
`TestAutomationExclusions` constants. Tags apply to every outline example.
57+
58+
## Karate
59+
60+
Tag the Scenario or Scenario Outline with `@datadog_no_auto_retry` and/or
61+
`@datadog_prevent_failure_suppression` (the names from the public
62+
`TestAutomationExclusions` constants). Both Karate 1.x and 2.x resolve these
63+
scenario tags before Datadog skipping and retry policy selection.

0 commit comments

Comments
 (0)