Skip to content

Commit 968588d

Browse files
committed
Expose and verify native MUnit automation exclusion declarations
1 parent 3f80d84 commit 968588d

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

‎dd-java-agent/instrumentation/junit/junit-4/junit-4-munit-0.7.28/src/test/groovy/MUnitTest.groovy‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import datadog.trace.instrumentation.junit4.MUnitUtils
88
import datadog.trace.instrumentation.junit4.TestEventsHandlerHolder
99
import org.example.TestFailedAssumptionMUnit
1010
import org.example.TestFailedMUnit
11+
import org.example.TestAutomationExcluded
1112
import org.example.TestFailedThenSucceedMUnit
1213
import org.example.TestSkippedMUnit
1314
import org.example.TestSkippedSuiteMUnit
@@ -21,6 +22,38 @@ class MUnitTest extends CiVisibilityInstrumentationTest {
2122

2223
def runner = new JUnitCore()
2324

25+
def "test automation exclusions preserve a blocking failure and execute once"() {
26+
given:
27+
def id = new TestFQN("org.example.TestAutomationExcluded", "protected_failure")
28+
givenDisabledTests([id])
29+
givenQuarantinedTests([id])
30+
givenAttemptToFixTests([id])
31+
givenFlakyRetryEnabled(true)
32+
givenFlakyTests([id])
33+
givenEarlyFlakinessDetectionEnabled(true)
34+
givenKnownTests([])
35+
36+
when:
37+
runTests([TestAutomationExcluded], false)
38+
39+
then:
40+
TEST_WRITER.toList().flatten().count { it.getTag("test.name") == "protected_failure" } == 1
41+
def testSpan = TEST_WRITER.toList().flatten().find { it.getTag("test.name") == "protected_failure" }
42+
testSpan != null
43+
testSpan.getTag("test.test_management.no_auto_retry") == true
44+
testSpan.getTag("test.test_management.prevent_failure_suppression") == true
45+
testSpan.getTag("test.test_management.is_test_disabled") == true
46+
testSpan.getTag("test.test_management.is_quarantined") == true
47+
testSpan.getTag("test.test_management.is_attempt_to_fix") == true
48+
testSpan.getTag("test.test_management.attempt_to_fix_passed") == null
49+
def skippedSpan = TEST_WRITER.toList().flatten().find { it.getTag("test.name") == "protected_skip" }
50+
skippedSpan != null
51+
skippedSpan.getTag("test.test_management.no_auto_retry") == true
52+
skippedSpan.getTag("test.test_management.prevent_failure_suppression") == true
53+
skippedSpan.getTag("test.status").toString() == "skip"
54+
}
55+
56+
2457
def "test #testcaseName"() {
2558
runTests(tests)
2659

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.example
2+
3+
import datadog.trace.api.civisibility.TestAutomationExclusions
4+
import munit.FunSuite
5+
6+
class TestAutomationExcluded extends FunSuite {
7+
private val noRetry = new munit.Tag(TestAutomationExclusions.NO_AUTO_RETRY)
8+
private val preventSuppression =
9+
new munit.Tag(TestAutomationExclusions.PREVENT_FAILURE_SUPPRESSION)
10+
11+
test("protected_failure".tag(noRetry).tag(preventSuppression)) {
12+
assert(false)
13+
}
14+
15+
test("protected_skip".tag(noRetry).tag(preventSuppression).ignore) {
16+
assert(false)
17+
}
18+
}

‎docs/test-automation-exclusions.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,21 @@ scenario tags before Datadog skipping and retry policy selection.
6767
Declare ScalaTest `Tag` instances from `TestAutomationExclusions.NO_AUTO_RETRY`
6868
and `PREVENT_FAILURE_SUPPRESSION`, then pass them to the test declaration.
6969
Native ignored tests remain ignored and carry their known exclusion tags.
70+
71+
## MUnit
72+
73+
Apply native MUnit tags using the public constants:
74+
75+
```scala
76+
import datadog.trace.api.civisibility.TestAutomationExclusions
77+
78+
test("critical behavior"
79+
.tag(new munit.Tag(TestAutomationExclusions.NO_AUTO_RETRY))
80+
.tag(new munit.Tag(TestAutomationExclusions.PREVENT_FAILURE_SUPPRESSION))) {
81+
assert(false)
82+
}
83+
```
84+
85+
MUnit's existing category bridge passes these declarations to the shared policy
86+
and reporter. Ignored tests retain their known tags. MUnit currently has no
87+
Datadog disabling capability; exclusions do not enable unsupported automation.

0 commit comments

Comments
 (0)