Skip to content
Closed
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 @@ -11,9 +11,11 @@
import datadog.trace.agent.tooling.muzzle.Reference;
import datadog.trace.agent.tooling.muzzle.ReferenceProvider;
import datadog.trace.api.Config;
import datadog.trace.api.civisibility.CIConstants;
import datadog.trace.api.civisibility.config.TestIdentifier;
import datadog.trace.api.civisibility.config.TestSourceData;
import datadog.trace.api.civisibility.execution.TestExecutionPolicy;
import datadog.trace.api.civisibility.telemetry.tag.SkipReason;
import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation;
import datadog.trace.bootstrap.CallDepthThreadLocalMap;
import datadog.trace.instrumentation.junit5.JUnitPlatformUtils;
Expand All @@ -28,6 +30,7 @@
import java.util.Map;
import net.bytebuddy.asm.Advice;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestTag;
import org.junit.platform.engine.support.hierarchical.EngineExecutionContext;
import org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutorService;
import org.junit.platform.engine.support.hierarchical.Node;
Expand All @@ -46,7 +49,9 @@ public JUnit5ExecutionInstrumentation() {

@Override
public boolean isEnabled() {
return super.isEnabled() && Config.get().isCiVisibilityExecutionPoliciesEnabled();
return super.isEnabled()
&& (Config.get().isCiVisibilityExecutionPoliciesEnabled()
|| Config.get().isCiVisibilityTestSkippingEnabled());
}

@Override
Expand Down Expand Up @@ -146,6 +151,26 @@ public static Boolean execute(@Advice.This HierarchicalTestExecutorService.TestT
TestIdentifier testIdentifier = TestDataFactory.createTestIdentifier(testDescriptor);
TestSourceData testSource = TestDataFactory.createTestSourceData(testDescriptor);
Collection<String> testTags = JUnitPlatformUtils.getTags(testDescriptor);

// skip before prepare() so the test-class instance is never constructed
SkipReason skipReason =
TestEventsHandlerHolder.HANDLERS.get(framework).skipReason(testIdentifier);
if (skipReason != null) {
boolean unskippable = false;
if (skipReason == SkipReason.ITR) {
for (TestTag tag : testDescriptor.getTags()) {
if (CIConstants.Tags.ITR_UNSKIPPABLE_TAG.equals(tag.getName())) {
unskippable = true;
break;
}
}
}
if (!unskippable) {
taskHandle.getListener().executionSkipped(testDescriptor, skipReason.getDescription());
return Boolean.TRUE;
}
}

TestExecutionPolicy executionPolicy =
TestEventsHandlerHolder.HANDLERS
.get(framework)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.example.TestSkipped
import org.example.TestSkippedClass
import org.example.TestSkippedNested
import org.example.TestSucceed
import org.example.TestSucceedAndFieldInitResource
import org.example.TestSucceedAndSkipped
import org.example.TestSucceedExpectedException
import org.example.TestSucceedNested
Expand Down Expand Up @@ -114,6 +115,20 @@ class JUnit5Test extends CiVisibilityInstrumentationTest {
"test-itr-unskippable-not-skipped" | [TestSucceedUnskippable] | []
}

def "test ITR does not construct skipped test class"() {
given:
TestSucceedAndFieldInitResource.CONSTRUCTOR_INVOCATIONS.set(0)
givenSkippableTests([
new TestIdentifier("org.example.TestSucceedAndFieldInitResource", "test_skippable", null)
])

when:
runTests([TestSucceedAndFieldInitResource])

then:
TestSucceedAndFieldInitResource.CONSTRUCTOR_INVOCATIONS.get() == 1
}

def "test flaky retries #testcaseName"() {
givenFlakyRetryEnabled(true)
givenFlakyTests(retriedTests)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.example;

import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;

public class TestSucceedAndFieldInitResource {

public static final AtomicInteger CONSTRUCTOR_INVOCATIONS = new AtomicInteger(0);

public TestSucceedAndFieldInitResource() {
CONSTRUCTOR_INVOCATIONS.incrementAndGet();
}

@Test
public void test_skippable() {}

@Test
public void test_runs() {}
}