Skip to content

Commit fe74f13

Browse files
committed
add test for attachment in cleanup
1 parent d94943d commit fe74f13

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

allure-spock2/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ plugins {
55
}
66

77
val spockFrameworkVersion = "2.3-groovy-3.0"
8-
val groovyVersion = "3.0.22"
8+
val spockTestVersion = "2.4-groovy-4.0"
9+
val groovyVersion = "4.0.29"
910

1011
dependencies {
1112
api(project(":allure-java-commons"))
@@ -16,13 +17,13 @@ dependencies {
1617
testAnnotationProcessor(project(":allure-descriptions-javadoc"))
1718
testImplementation("io.github.glytching:junit-extensions")
1819
testImplementation("org.assertj:assertj-core")
19-
testImplementation("org.codehaus.groovy:groovy:${groovyVersion}")
20+
testImplementation("org.apache.groovy:groovy:${groovyVersion}")
2021
testImplementation("org.junit.jupiter:junit-jupiter-api")
2122
testImplementation("org.junit.jupiter:junit-jupiter-params")
2223
testImplementation("org.junit.platform:junit-platform-launcher")
2324
testImplementation("org.mockito:mockito-core")
2425
testImplementation("org.slf4j:slf4j-simple")
25-
testImplementation("org.spockframework:spock-core:$spockFrameworkVersion")
26+
testImplementation("org.spockframework:spock-core:$spockTestVersion")
2627
testImplementation(project(":allure-assertj"))
2728
testImplementation(project(":allure-java-commons-test"))
2829
testImplementation(project(":allure-junit-platform"))
@@ -58,4 +59,3 @@ publishing {
5859
}
5960
}
6061
}
61-

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.qameta.allure.model.StepResult;
2727
import io.qameta.allure.model.TestResult;
2828
import io.qameta.allure.model.TestResultContainer;
29+
import io.qameta.allure.spock2.samples.CleanupAttachmentFailedTest;
2930
import io.qameta.allure.spock2.samples.BrokenTest;
3031
import io.qameta.allure.spock2.samples.DataDrivenTest;
3132
import io.qameta.allure.spock2.samples.DerivedSpec;
@@ -64,6 +65,7 @@
6465
import org.mockito.ArgumentCaptor;
6566

6667
import java.lang.reflect.Method;
68+
import java.nio.charset.StandardCharsets;
6769
import java.time.Instant;
6870
import java.util.Arrays;
6971
import java.util.Collection;
@@ -245,6 +247,22 @@ void shouldProcessFailedTest() {
245247
.containsExactly(Status.FAILED);
246248
}
247249

250+
@Test
251+
void shouldAttachCleanupAttachmentOnFailedTest() {
252+
final AllureResults results = runClasses(CleanupAttachmentFailedTest.class);
253+
final TestResult testResult = results.getTestResultByName("failed test with cleanup attachment");
254+
255+
assertThat(testResult.getStatus()).isEqualTo(Status.FAILED);
256+
assertThat(testResult.getAttachments())
257+
.extracting(io.qameta.allure.model.Attachment::getName, io.qameta.allure.model.Attachment::getType)
258+
.containsExactly(tuple("cleanup attachment", "text/plain"));
259+
260+
final String source = testResult.getAttachments().get(0).getSource();
261+
assertThat(results.getAttachments()).containsKey(source);
262+
assertThat(results.getAttachments().get(source))
263+
.containsExactly("attachment from cleanup".getBytes(StandardCharsets.UTF_8));
264+
}
265+
248266
@Test
249267
void shouldProcessBrokenTest() {
250268
final AllureResults results = runClasses(BrokenTest.class);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2016-2026 Qameta Software Inc
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 io.qameta.allure.Allure
19+
import spock.lang.Specification
20+
21+
class CleanupAttachmentFailedTest extends Specification {
22+
23+
def "failed test with cleanup attachment"() {
24+
expect:
25+
false
26+
27+
cleanup:
28+
Allure.addAttachment("cleanup attachment", "text/plain", "attachment from cleanup", ".txt")
29+
}
30+
}

0 commit comments

Comments
 (0)