From fe74f1371ce3e3228329189e139ff7644f052b50 Mon Sep 17 00:00:00 2001 From: Dmitry Baev Date: Tue, 31 Mar 2026 20:36:15 +0100 Subject: [PATCH] add test for attachment in cleanup --- allure-spock2/build.gradle.kts | 8 ++--- .../allure/spock2/AllureSpock2Test.java | 18 +++++++++++ .../CleanupAttachmentFailedTest.groovy | 30 +++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 allure-spock2/src/test/groovy/io/qameta/allure/spock2/samples/CleanupAttachmentFailedTest.groovy diff --git a/allure-spock2/build.gradle.kts b/allure-spock2/build.gradle.kts index 1a1226597..2ec1d67a0 100644 --- a/allure-spock2/build.gradle.kts +++ b/allure-spock2/build.gradle.kts @@ -5,7 +5,8 @@ plugins { } val spockFrameworkVersion = "2.3-groovy-3.0" -val groovyVersion = "3.0.22" +val spockTestVersion = "2.4-groovy-4.0" +val groovyVersion = "4.0.29" dependencies { api(project(":allure-java-commons")) @@ -16,13 +17,13 @@ dependencies { testAnnotationProcessor(project(":allure-descriptions-javadoc")) testImplementation("io.github.glytching:junit-extensions") testImplementation("org.assertj:assertj-core") - testImplementation("org.codehaus.groovy:groovy:${groovyVersion}") + testImplementation("org.apache.groovy:groovy:${groovyVersion}") testImplementation("org.junit.jupiter:junit-jupiter-api") testImplementation("org.junit.jupiter:junit-jupiter-params") testImplementation("org.junit.platform:junit-platform-launcher") testImplementation("org.mockito:mockito-core") testImplementation("org.slf4j:slf4j-simple") - testImplementation("org.spockframework:spock-core:$spockFrameworkVersion") + testImplementation("org.spockframework:spock-core:$spockTestVersion") testImplementation(project(":allure-assertj")) testImplementation(project(":allure-java-commons-test")) testImplementation(project(":allure-junit-platform")) @@ -58,4 +59,3 @@ publishing { } } } - diff --git a/allure-spock2/src/test/groovy/io/qameta/allure/spock2/AllureSpock2Test.java b/allure-spock2/src/test/groovy/io/qameta/allure/spock2/AllureSpock2Test.java index 3771a655d..fb34ed35f 100644 --- a/allure-spock2/src/test/groovy/io/qameta/allure/spock2/AllureSpock2Test.java +++ b/allure-spock2/src/test/groovy/io/qameta/allure/spock2/AllureSpock2Test.java @@ -26,6 +26,7 @@ import io.qameta.allure.model.StepResult; import io.qameta.allure.model.TestResult; import io.qameta.allure.model.TestResultContainer; +import io.qameta.allure.spock2.samples.CleanupAttachmentFailedTest; import io.qameta.allure.spock2.samples.BrokenTest; import io.qameta.allure.spock2.samples.DataDrivenTest; import io.qameta.allure.spock2.samples.DerivedSpec; @@ -64,6 +65,7 @@ import org.mockito.ArgumentCaptor; import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.Arrays; import java.util.Collection; @@ -245,6 +247,22 @@ void shouldProcessFailedTest() { .containsExactly(Status.FAILED); } + @Test + void shouldAttachCleanupAttachmentOnFailedTest() { + final AllureResults results = runClasses(CleanupAttachmentFailedTest.class); + final TestResult testResult = results.getTestResultByName("failed test with cleanup attachment"); + + assertThat(testResult.getStatus()).isEqualTo(Status.FAILED); + assertThat(testResult.getAttachments()) + .extracting(io.qameta.allure.model.Attachment::getName, io.qameta.allure.model.Attachment::getType) + .containsExactly(tuple("cleanup attachment", "text/plain")); + + final String source = testResult.getAttachments().get(0).getSource(); + assertThat(results.getAttachments()).containsKey(source); + assertThat(results.getAttachments().get(source)) + .containsExactly("attachment from cleanup".getBytes(StandardCharsets.UTF_8)); + } + @Test void shouldProcessBrokenTest() { final AllureResults results = runClasses(BrokenTest.class); diff --git a/allure-spock2/src/test/groovy/io/qameta/allure/spock2/samples/CleanupAttachmentFailedTest.groovy b/allure-spock2/src/test/groovy/io/qameta/allure/spock2/samples/CleanupAttachmentFailedTest.groovy new file mode 100644 index 000000000..069036aa9 --- /dev/null +++ b/allure-spock2/src/test/groovy/io/qameta/allure/spock2/samples/CleanupAttachmentFailedTest.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2016-2026 Qameta Software Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.qameta.allure.spock2.samples + +import io.qameta.allure.Allure +import spock.lang.Specification + +class CleanupAttachmentFailedTest extends Specification { + + def "failed test with cleanup attachment"() { + expect: + false + + cleanup: + Allure.addAttachment("cleanup attachment", "text/plain", "attachment from cleanup", ".txt") + } +}