Skip to content

Commit 163dd5b

Browse files
authored
[xray-exporter] Use scenario title as description for new test cases (#5752)
1 parent cd23f91 commit 163dd5b

File tree

10 files changed

+72
-6
lines changed

10 files changed

+72
-6
lines changed

docs/modules/integrations/pages/xray-exporter.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ Please make sure that the `bdd.configuration.formats` property includes JSON val
6060
|false
6161
|Comma-separated list of file and folder paths that should be uploaded to test execution as attachments. Please note that regular files like images, texts are uploaded as is, whereas folders are archived before the upload.
6262

63+
|`xray-exporter.test-case.use-scenario-title-as-description`
64+
|false
65+
|If enabled (`true` value), the scenario title will be used as the description, but *only* for newly created test cases, otherwise the description will be left empty.
66+
6367
|===
6468

6569
.application.properties

vividus-to-xray-exporter/src/main/java/org/vividus/xray/configuration/XrayExporterOptions.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 the original author or authors.
2+
* Copyright 2019-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ public class XrayExporterOptions
3030
private String testExecutionSummary;
3131
private List<Path> testExecutionAttachments;
3232
private boolean testCaseUpdatesEnabled;
33+
private TestCase testCase;
3334

3435
public Path getJsonResultsDirectory()
3536
{
@@ -90,4 +91,29 @@ public void setTestCaseUpdatesEnabled(boolean testCaseUpdatesEnabled)
9091
{
9192
this.testCaseUpdatesEnabled = testCaseUpdatesEnabled;
9293
}
94+
95+
public TestCase getTestCase()
96+
{
97+
return testCase;
98+
}
99+
100+
public void setTestCase(TestCase testCase)
101+
{
102+
this.testCase = testCase;
103+
}
104+
105+
public static final class TestCase
106+
{
107+
private boolean useScenarioTitleAsDescription;
108+
109+
public boolean isUseScenarioTitleAsDescription()
110+
{
111+
return useScenarioTitleAsDescription;
112+
}
113+
114+
public void setUseScenarioTitleAsDescription(boolean useScenarioTitleAsDescription)
115+
{
116+
this.useScenarioTitleAsDescription = useScenarioTitleAsDescription;
117+
}
118+
}
93119
}

vividus-to-xray-exporter/src/main/java/org/vividus/xray/databind/AbstractTestCaseSerializer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 the original author or authors.
2+
* Copyright 2019-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,6 +64,12 @@ public void serialize(T testCase, JsonGenerator generator, SerializerProvider se
6464

6565
generator.writeStringField("summary", testCase.getSummary());
6666

67+
String description = testCase.getDescription();
68+
if (description != null)
69+
{
70+
generator.writeStringField("description", testCase.getDescription());
71+
}
72+
6773
writeJsonArray(generator, "labels", testCase.getLabels(), false);
6874

6975
writeJsonArray(generator, "components", testCase.getComponents(), true);

vividus-to-xray-exporter/src/main/java/org/vividus/xray/exporter/XrayExporter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ private Optional<Entry<String, Scenario>> exportScenario(String storyTitle, Scen
154154
AbstractTestCase testCase = testCaseFactories.get(testCaseType).apply(parameters);
155155
if (testCaseId == null)
156156
{
157+
if (xrayExporterOptions.getTestCase().isUseScenarioTitleAsDescription())
158+
{
159+
testCase.setDescription(scenario.getTitle());
160+
}
161+
157162
testCaseId = xrayFacade.createTestCase(testCase);
158163
}
159164
else if (xrayExporterOptions.isTestCaseUpdatesEnabled())

vividus-to-xray-exporter/src/main/java/org/vividus/xray/model/AbstractTestCase.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020 the original author or authors.
2+
* Copyright 2019-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ public abstract class AbstractTestCase
2424
private String projectKey;
2525
private String assignee;
2626
private String summary;
27+
private String description;
2728
private Set<String> labels;
2829
private Set<String> components;
2930

@@ -67,6 +68,16 @@ public void setSummary(String summary)
6768
this.summary = summary;
6869
}
6970

71+
public String getDescription()
72+
{
73+
return description;
74+
}
75+
76+
public void setDescription(String description)
77+
{
78+
this.description = description;
79+
}
80+
7081
public Set<String> getLabels()
7182
{
7283
return labels;

vividus-to-xray-exporter/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ xray-exporter.editable-statuses=
33
xray-exporter.jira-instance-key=
44
xray-exporter.test-case-updates-enabled=true
55
xray-exporter.test-execution-attachments=
6+
xray-exporter.test-case.use-scenario-title-as-description=false

vividus-to-xray-exporter/src/test/java/org/vividus/xray/databind/ManualTestCaseSerializerTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 the original author or authors.
2+
* Copyright 2019-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,6 +76,7 @@ private static ManualTestCase createBaseTest()
7676
test.setType(TestCaseType.MANUAL.getValue());
7777
test.setProjectKey(PROJECT_KEY);
7878
test.setSummary("summary");
79+
test.setDescription("description");
7980
test.setManualTestSteps(List.of(
8081
createStep("action 1", "data 1", "result 1"),
8182
createStep("action 2", "data 2", "result 2")

vividus-to-xray-exporter/src/test/java/org/vividus/xray/exporter/XrayExporterTests.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 the original author or authors.
2+
* Copyright 2019-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
3131
import static org.mockito.ArgumentMatchers.eq;
3232
import static org.mockito.Mockito.doThrow;
3333
import static org.mockito.Mockito.mock;
34+
import static org.mockito.Mockito.never;
3435
import static org.mockito.Mockito.verify;
3536
import static org.mockito.Mockito.verifyNoInteractions;
3637
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -72,6 +73,7 @@
7273
import org.vividus.output.ManualTestStep;
7374
import org.vividus.util.ResourceUtils;
7475
import org.vividus.xray.configuration.XrayExporterOptions;
76+
import org.vividus.xray.configuration.XrayExporterOptions.TestCase;
7577
import org.vividus.xray.facade.AbstractTestCaseParameters;
7678
import org.vividus.xray.facade.CucumberTestCaseParameters;
7779
import org.vividus.xray.facade.ManualTestCaseParameters;
@@ -116,6 +118,7 @@ void beforeEach()
116118
{
117119
xrayExporterOptions.setTestCaseUpdatesEnabled(true);
118120
xrayExporterOptions.setTestExecutionAttachments(List.of(ROOT));
121+
xrayExporterOptions.setTestCase(new TestCase());
119122
}
120123

121124
@AfterEach
@@ -130,6 +133,7 @@ void shouldExportCucumberTestCaseWithoutTestCaseId() throws URISyntaxException,
130133
{
131134
URI jsonResultsUri = getJsonResultsUri("createcucumber");
132135
xrayExporterOptions.setJsonResultsDirectory(Paths.get(jsonResultsUri));
136+
xrayExporterOptions.getTestCase().setUseScenarioTitleAsDescription(false);
133137
CucumberTestCase testCase = mock(CucumberTestCase.class);
134138

135139
when(xrayFacade.createTestCase(testCase)).thenReturn(ISSUE_ID);
@@ -147,6 +151,7 @@ void shouldExportCucumberTestCaseWithoutTestCaseId() throws URISyntaxException,
147151
+ "|parameter-value-3|" + lineSeparator();
148152
verifyCucumberTestCaseParameters("Scenario Outline", scenario);
149153
validateLogs(jsonResultsUri, getExportingScenarioEvent(), getExportSuccessfulEvent());
154+
verify(testCase, never()).setDescription(any());
150155
}
151156

152157
@Test
@@ -155,6 +160,7 @@ void shouldUpdateExistingCucumberTestCase() throws URISyntaxException, IOExcepti
155160
{
156161
URI jsonResultsUri = getJsonResultsUri(UPDATECUCUMBER_RESOURCE_KEY);
157162
xrayExporterOptions.setJsonResultsDirectory(Paths.get(jsonResultsUri));
163+
xrayExporterOptions.getTestCase().setUseScenarioTitleAsDescription(true);
158164
CucumberTestCase testCase = mock(CucumberTestCase.class);
159165

160166
when(testCaseFactory.createCucumberTestCase(cucumberTestCaseParametersCaptor.capture())).thenReturn(testCase);
@@ -165,6 +171,7 @@ void shouldUpdateExistingCucumberTestCase() throws URISyntaxException, IOExcepti
165171
String scenario = GIVEN_STEP + lineSeparator() + WHEN_STEP + lineSeparator() + THEN_STEP;
166172
verifyCucumberTestCaseParameters("Scenario", scenario);
167173
validateLogs(jsonResultsUri, getExportingScenarioEvent(), getExportSuccessfulEvent());
174+
verify(testCase, never()).setDescription(any());
168175
}
169176

170177
@Test
@@ -281,10 +288,12 @@ void shouldFailIfResultsDirectoryIsEmpty(@TempDir Path sourceDirectory)
281288
}
282289

283290
@Test
284-
void shouldExportNewTestAndLinkToRequirements() throws URISyntaxException, IOException, JiraConfigurationException
291+
void shouldExportNewTestAndLinkToRequirementsAndUseScenarioTitleAsTestCaseDescription()
292+
throws URISyntaxException, IOException, JiraConfigurationException
285293
{
286294
URI jsonResultsUri = getJsonResultsUri("createandlink");
287295
xrayExporterOptions.setJsonResultsDirectory(Paths.get(jsonResultsUri));
296+
xrayExporterOptions.getTestCase().setUseScenarioTitleAsDescription(true);
288297
ManualTestCase testCase = mock(ManualTestCase.class);
289298

290299
when(xrayFacade.createTestCase(testCase)).thenReturn(ISSUE_ID);
@@ -296,6 +305,7 @@ void shouldExportNewTestAndLinkToRequirements() throws URISyntaxException, IOExc
296305

297306
verifyManualTestCaseParameters(Set.of(), Set.of());
298307
validateLogs(jsonResultsUri, getExportingScenarioEvent(), getExportSuccessfulEvent());
308+
verify(testCase).setDescription(SCENARIO_TITLE);
299309
}
300310

301311
@Test

vividus-to-xray-exporter/src/test/resources/org/vividus/xray/databind/manual.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"value": "Manual"
1414
},
1515
"summary": "summary",
16+
"description": "description",
1617
"labels": [
1718
"label 1",
1819
"label 2"

vividus-to-xray-exporter/src/test/resources/org/vividus/xray/databind/nullable.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"value": "Manual"
1111
},
1212
"summary": "summary",
13+
"description": "description",
1314
"manual-steps-field": {
1415
"steps": [
1516
{

0 commit comments

Comments
 (0)