Skip to content

Commit 686028b

Browse files
authored
fix(spock2): add support for test tags (via #974)
1 parent 12f8842 commit 686028b

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

allure-spock2/src/main/java/io/qameta/allure/spock2/AllureSpock2.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.spockframework.runtime.model.MethodInfo;
4343
import org.spockframework.runtime.model.MethodKind;
4444
import org.spockframework.runtime.model.SpecInfo;
45+
import org.spockframework.runtime.model.TestTag;
4546

4647
import java.lang.reflect.Method;
4748
import java.security.MessageDigest;
@@ -185,6 +186,12 @@ public void beforeIteration(final IterationInfo iteration) {
185186
labels.add(createParentSuiteLabel(superSpec.getName()));
186187
}
187188

189+
final List<Label> testTags = feature.getTestTags().stream()
190+
.map(TestTag::getValue)
191+
.map(ResultsUtils::createTagLabel)
192+
.collect(Collectors.toList());
193+
194+
labels.addAll(testTags);
188195
labels.addAll(featureLabels);
189196
labels.addAll(specLabels);
190197
labels.addAll(getProvidedLabels());

allure-spock2/src/test/groovy/io/qameta/allure/spock2/AllureSpock2Test.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import io.qameta.allure.spock2.samples.OneTest;
4040
import io.qameta.allure.spock2.samples.ParametersTest;
4141
import io.qameta.allure.spock2.samples.SpecFixtures;
42+
import io.qameta.allure.spock2.samples.SpockTags;
4243
import io.qameta.allure.spock2.samples.StepsAndBlocks;
4344
import io.qameta.allure.spock2.samples.TestWithAnnotations;
4445
import io.qameta.allure.spock2.samples.TestWithAnnotationsOnClass;
@@ -219,6 +220,19 @@ void shouldProcessMethodAnnotations() {
219220
);
220221
}
221222

223+
@Test
224+
void shouldProcessSpockTags() {
225+
final AllureResults results = runClasses(SpockTags.class);
226+
assertThat(results.getTestResults())
227+
.hasSize(1)
228+
.flatExtracting(TestResult::getLabels)
229+
.extracting(Label::getName, Label::getValue)
230+
.contains(
231+
tuple("tag", "first"),
232+
tuple("tag", "second")
233+
);
234+
}
235+
222236
@Test
223237
void shouldProcessClassAnnotations() {
224238
final AllureResults results = runClasses(TestWithAnnotationsOnClass.class);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2019 Qameta Software OÜ
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.spock2.samples
17+
18+
import spock.lang.Specification
19+
import spock.lang.Tag
20+
21+
/**
22+
* @author charlie (Dmitry Baev).
23+
*/
24+
class SpockTags extends Specification {
25+
26+
@Tag("first")
27+
@Tag("second")
28+
def "someTest"() {
29+
expect:
30+
true
31+
}
32+
}

0 commit comments

Comments
 (0)