From 31d2f1c353c9fc3256c97f521e31b893f3ec0557 Mon Sep 17 00:00:00 2001 From: elantsov Date: Fri, 26 Mar 2021 02:39:58 +0300 Subject: [PATCH] Fix updates in Cucumber tests with fixtures --- .../io/qameta/allure/AllureLifecycle.java | 2 - .../io/qameta/allure/AllureLifecycleTest.java | 61 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/allure-java-commons/src/main/java/io/qameta/allure/AllureLifecycle.java b/allure-java-commons/src/main/java/io/qameta/allure/AllureLifecycle.java index 7af06dd71..b22528e3e 100644 --- a/allure-java-commons/src/main/java/io/qameta/allure/AllureLifecycle.java +++ b/allure-java-commons/src/main/java/io/qameta/allure/AllureLifecycle.java @@ -220,7 +220,6 @@ private void startFixture(final String uuid, final FixtureResult result) { storage.put(uuid, result); result.setStage(Stage.RUNNING); result.setStart(System.currentTimeMillis()); - threadContext.clear(); threadContext.start(uuid); } @@ -276,7 +275,6 @@ public void stopFixture(final String uuid) { fixture.setStop(System.currentTimeMillis()); storage.remove(uuid); - threadContext.clear(); notifier.afterFixtureStop(fixture); } diff --git a/allure-java-commons/src/test/java/io/qameta/allure/AllureLifecycleTest.java b/allure-java-commons/src/test/java/io/qameta/allure/AllureLifecycleTest.java index 35ea19d86..742777676 100644 --- a/allure-java-commons/src/test/java/io/qameta/allure/AllureLifecycleTest.java +++ b/allure-java-commons/src/test/java/io/qameta/allure/AllureLifecycleTest.java @@ -225,6 +225,67 @@ void shouldUpdateTest() { .containsExactly(stepName); } + @Test + void shouldUpdateTestWithFixture() { + final String containerUuid = randomId(); + final String containerName = randomName(); + + TestResultContainer container = new TestResultContainer() + .setUuid(containerUuid) + .setName(containerName); + lifecycle.startTestContainer(container); + + final String uuid = randomId(); + final String name = randomName(); + + final TestResult result = new TestResult().setUuid(uuid).setName(name); + lifecycle.scheduleTestCase(result); + lifecycle.startTestCase(uuid); + + final String firstUuid = randomId(); + final String firstName = randomName(); + final FixtureResult first = new FixtureResult().setName(firstName); + + lifecycle.startPrepareFixture(containerUuid, firstUuid, first); + lifecycle.stopFixture(firstUuid); + + final String stepUuid = randomId(); + final String stepName = randomName(); + + final StepResult step = new StepResult().setName(stepName); + lifecycle.startStep(uuid, stepUuid, step); + + final String description = randomName(); + final String fullName = randomName(); + + lifecycle.updateTestCase(uuid, testResult -> testResult.setDescription(description)); + lifecycle.updateTestCase(testResult -> testResult.setFullName(fullName)); + + lifecycle.stopStep(stepUuid); + + lifecycle.stopTestCase(uuid); + + lifecycle.stopTestContainer(containerUuid); + + lifecycle.writeTestCase(uuid); + lifecycle.writeTestContainer(containerUuid); + + final ArgumentCaptor captor = forClass(TestResult.class); + verify(writer, times(1)).write(captor.capture()); + + final TestResult actual = captor.getValue(); + assertThat(actual) + .isNotNull() + .hasFieldOrPropertyWithValue("uuid", uuid) + .hasFieldOrPropertyWithValue("description", description) + .hasFieldOrPropertyWithValue("name", name) + .hasFieldOrPropertyWithValue("fullName", fullName); + + assertThat(actual.getSteps()) + .flatExtracting(StepResult::getName) + .containsExactly(stepName); + } + @Test void shouldUpdateContainer() { final String uuid = randomId();