[Cucumber for Java] Unify tree of test for Cucumber 2, 3 and later

The "name" field of object representing TestCase in Cucumber library has different value in v2 and v3. To unify names in the tree of tests this should be handled at Formatter level.

IDEA-203098 Cucumber Scenario Outline doesn't show Examples

GitOrigin-RevId: 7d58061e33139b66548b4e9f404d10b5520b2c32
This commit is contained in:
Andrey Vokin
2019-08-03 14:02:42 +03:00
committed by intellij-monorepo-bot
parent a8b29e1dbc
commit d94436ad53
2 changed files with 11 additions and 17 deletions
@@ -120,7 +120,7 @@ public class CucumberJvm2SMFormatter implements Formatter {
!currentFilePath.equals(getEventUri(event))) {
closeCurrentScenarioOutline();
currentScenarioOutlineLine = mainScenarioLine;
currentScenarioOutlineName = getEventName(event);
currentScenarioOutlineName = getScenarioNameFromTestCase(event.testCase);
outCommand(TEMPLATE_TEST_SUITE_STARTED, getCurrentTime(), getEventUri(event) + ":" + currentScenarioOutlineLine,
currentScenarioOutlineName);
outCommand(TEMPLATE_TEST_SUITE_STARTED, getCurrentTime(), "", EXAMPLES_CAPTION);
@@ -261,7 +261,7 @@ public class CucumberJvm2SMFormatter implements Formatter {
private static PickleEvent getPickleEvent(TestCase testCase) {
try {
Field pickleEventField = TestCase.class.getDeclaredField("pickleEvent");
Field pickleEventField = testCase.getClass().getDeclaredField("pickleEvent");
pickleEventField.setAccessible(true);
return (PickleEvent)pickleEventField.get(testCase);
}
@@ -283,18 +283,22 @@ public class CucumberJvm2SMFormatter implements Formatter {
return 0;
}
private static String getScenarioName(TestCase testCase) {
private String getScenarioName(TestCase testCase) {
if (isScenarioOutline(testCase)) {
return SCENARIO_OUTLINE_CAPTION + testCase.getLine();
}
return getScenarioNameFromTestCase(testCase);
}
protected String getScenarioNameFromTestCase(TestCase testCase) {
return testCase.getName();
}
protected String getScenarioName(TestCaseStarted testCaseStarted) {
private String getScenarioName(TestCaseStarted testCaseStarted) {
return getScenarioName(testCaseStarted.testCase);
}
protected String getScenarioName(TestCaseFinished testCaseFinished) {
private String getScenarioName(TestCaseFinished testCaseFinished) {
return getScenarioName(testCaseFinished.testCase);
}
@@ -4,7 +4,6 @@ import cucumber.api.HookTestStep;
import cucumber.api.PickleStepTestStep;
import cucumber.api.TestCase;
import cucumber.api.TestStep;
import cucumber.api.event.TestCaseFinished;
import cucumber.api.event.TestCaseStarted;
import cucumber.api.event.TestStepFinished;
import cucumber.api.event.TestStepStarted;
@@ -35,16 +34,6 @@ public class CucumberJvm3SMFormatter extends CucumberJvm2SMFormatter {
return event.testCase.getName();
}
@Override
protected String getScenarioName(TestCaseStarted testCaseStarted) {
return getScenarioName(testCaseStarted.testCase);
}
@Override
protected String getScenarioName(TestCaseFinished testCaseFinished) {
return getScenarioName(testCaseFinished.testCase);
}
@Override
protected String getStepLocation(TestStepStarted testStepStarted) {
return getStepLocation(testStepStarted.testStep);
@@ -65,7 +54,8 @@ public class CucumberJvm3SMFormatter extends CucumberJvm2SMFormatter {
return getStepName(testStepFinished.testStep);
}
private static String getScenarioName(TestCase testCase) {
@Override
protected String getScenarioNameFromTestCase(TestCase testCase) {
return "Scenario: " + testCase.getName();
}