Repository navigation
Support test automation exclusions in Spock #12943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
calvinbayer
wants to merge
4
commits into
codex/testng-automation-exclusions
Choose a base branch
from
codex/spock-automation-exclusions
base: codex/testng-automation-exclusions
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6446ac7
Apply automation exclusions to Spock features and spec selection
calvinbayer f6b686e
Honor inherited Spock feature exclusion declarations
calvinbayer db50c6f
Resolve inherited Spock features by declaration identity
calvinbayer 144197a
Use declaring source files for inherited test methods
calvinbayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...i-visibility/src/test/java/datadog/trace/civisibility/domain/InheritedTestSourceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| package datadog.trace.civisibility.domain; | ||
|
|
||
| import static java.util.Collections.emptyList; | ||
| import static java.util.Collections.singletonList; | ||
| import static java.util.Collections.singletonMap; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.anyString; | ||
| import static org.mockito.Mockito.RETURNS_SELF; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import datadog.trace.api.Config; | ||
| import datadog.trace.api.DDTraceId; | ||
| import datadog.trace.api.civisibility.config.TestSourceData; | ||
| import datadog.trace.api.civisibility.coverage.CoveragePerTestBridge; | ||
| import datadog.trace.api.civisibility.coverage.NoOpCoverageStore; | ||
| import datadog.trace.api.civisibility.telemetry.NoOpMetricCollector; | ||
| import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentTracer; | ||
| import datadog.trace.bootstrap.instrumentation.api.Tags; | ||
| import datadog.trace.civisibility.codeowners.NoCodeowners; | ||
| import datadog.trace.civisibility.config.ConfigurationErrors; | ||
| import datadog.trace.civisibility.config.ExecutionSettings; | ||
| import datadog.trace.civisibility.decorator.TestDecorator; | ||
| import datadog.trace.civisibility.diff.LineDiff; | ||
| import datadog.trace.civisibility.source.LinesResolver; | ||
| import datadog.trace.civisibility.source.SourcePathResolver; | ||
| import datadog.trace.civisibility.test.ExecutionResults; | ||
| import datadog.trace.civisibility.test.ExecutionStrategy; | ||
| import java.lang.reflect.Method; | ||
| import java.util.BitSet; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| class InheritedTestSourceTest { | ||
| private static final String PARENT_SOURCE = "src/test/java/ParentSpec.java"; | ||
| private static final String LEAF_SOURCE = "src/test/java/LeafSpec.java"; | ||
|
|
||
| static class ParentSpec { | ||
| public void feature() {} | ||
| } | ||
|
|
||
| static class LeafSpec extends ParentSpec {} | ||
|
|
||
| @Test | ||
| void reportsParentSourceAndLinesWhilePreservingConcreteSuiteIdentity() throws Exception { | ||
| Method method = ParentSpec.class.getDeclaredMethod("feature"); | ||
| SourcePathResolver sourcePaths = sourcePaths(); | ||
| LinesResolver lines = mock(LinesResolver.class); | ||
| when(lines.getMethodLines(method)).thenReturn(new LinesResolver.Lines(10, 15)); | ||
| AgentSpan span = mock(AgentSpan.class); | ||
| AgentTracer.SpanBuilder builder = mock(AgentTracer.SpanBuilder.class, RETURNS_SELF); | ||
| when(builder.start()).thenReturn(span); | ||
| AgentTracer.TracerAPI tracer = mock(AgentTracer.TracerAPI.class); | ||
| when(tracer.buildSpan(anyString(), any())).thenReturn(builder); | ||
| AgentSpanContext context = mock(AgentSpanContext.class); | ||
| when(context.getTraceId()).thenReturn(DDTraceId.ONE); | ||
| Config config = mock(Config.class); | ||
| when(config.isCiVisibilitySourceDataEnabled()).thenReturn(true); | ||
| TestDecorator decorator = mock(TestDecorator.class); | ||
| when(decorator.component()).thenReturn("spock"); | ||
| AgentTracer.TracerAPI original = AgentTracer.get(); | ||
| AgentTracer.forceRegister(tracer); | ||
| try { | ||
| new TestImpl( | ||
| context, | ||
| 1L, | ||
| "module", | ||
| LeafSpec.class.getName(), | ||
| "feature", | ||
| null, | ||
| null, | ||
| false, | ||
| null, | ||
| LeafSpec.class, | ||
| method, | ||
| InstrumentationType.BUILD, | ||
| TestFrameworkInstrumentation.SPOCK, | ||
| config, | ||
| NoOpMetricCollector.INSTANCE, | ||
| decorator, | ||
| sourcePaths, | ||
| lines, | ||
| NoCodeowners.INSTANCE, | ||
| new NoOpCoverageStore.Factory(), | ||
| new ExecutionResults(), | ||
| ConfigurationErrors.NONE, | ||
| emptyList(), | ||
| ignored -> {}); | ||
|
|
||
| verify(span).setTag(Tags.TEST_SUITE, LeafSpec.class.getName()); | ||
| verify(span).setTag(Tags.TEST_SOURCE_FILE, PARENT_SOURCE); | ||
| verify(span).setTag(Tags.TEST_SOURCE_START, 10); | ||
| verify(span).setTag(Tags.TEST_SOURCE_END, 15); | ||
| } finally { | ||
| CoveragePerTestBridge.removeThreadLocalCoverageProbes(); | ||
| AgentTracer.forceRegister(original); | ||
| } | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(booleans = {true, false}) | ||
| void checksModifiedLinesInTheDeclaringSource(boolean parentModified) throws Exception { | ||
| Method method = ParentSpec.class.getDeclaredMethod("feature"); | ||
| BitSet changedLines = new BitSet(); | ||
| changedLines.set(12); | ||
| ExecutionSettings settings = mock(ExecutionSettings.class); | ||
| when(settings.getPullRequestDiff()) | ||
| .thenReturn( | ||
| new LineDiff(singletonMap(parentModified ? PARENT_SOURCE : LEAF_SOURCE, changedLines))); | ||
| LinesResolver lines = mock(LinesResolver.class); | ||
| when(lines.getMethodLines(method)).thenReturn(new LinesResolver.Lines(10, 15)); | ||
| ExecutionStrategy strategy = | ||
| new ExecutionStrategy(mock(Config.class), settings, sourcePaths(), lines); | ||
|
|
||
| assertEquals( | ||
| parentModified, strategy.isModified(new TestSourceData(LeafSpec.class, method, "feature"))); | ||
| } | ||
|
|
||
| private static SourcePathResolver sourcePaths() { | ||
| SourcePathResolver resolver = mock(SourcePathResolver.class); | ||
| when(resolver.getSourcePaths(ParentSpec.class)).thenReturn(singletonList(PARENT_SOURCE)); | ||
| when(resolver.getSourcePaths(LeafSpec.class)).thenReturn(singletonList(LEAF_SOURCE)); | ||
| return resolver; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...junit/junit-5/junit-5-spock-2.0/src/test/groovy/org/example/TestAutomationExcluded.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package org.example | ||
|
|
||
| import datadog.trace.api.civisibility.NoAutoRetry | ||
| import datadog.trace.api.civisibility.PreventFailureSuppression | ||
| import spock.lang.Specification | ||
|
|
||
| class TestAutomationExcluded extends Specification { | ||
| static int executions | ||
|
|
||
| @NoAutoRetry | ||
| @PreventFailureSuppression | ||
| def "protected_failure"() { | ||
| expect: | ||
| ++executions < 0 | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
.../junit-5-spock-2.0/src/test/groovy/org/example/TestAutomationExcludedCollisionBase.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package org.example | ||
|
|
||
| import spock.lang.Specification | ||
|
|
||
| class TestAutomationExcludedCollisionBase extends Specification { | ||
| static int normalExecutions | ||
|
|
||
| def "same_named_feature"() { | ||
| expect: | ||
| ++normalExecutions < 0 | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
.../junit-5-spock-2.0/src/test/groovy/org/example/TestAutomationExcludedCollisionLeaf.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package org.example | ||
|
|
||
| class TestAutomationExcludedCollisionLeaf extends TestAutomationExcludedCollisionMiddle {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.