-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TestNG] Remove spurious Optional[<Feature Name>] from test name
When executing tests, the test name would be displayed as: ``` RunCucumberTest.runScenario["Another Addition", "Optional[Basic Arithmetic]"] ``` Which should have been: ``` RunCucumberTest.runScenario["Many additions", "Basic Arithmetic"] ```
- Loading branch information
1 parent
65dfc97
commit 0a9cdcd
Showing
5 changed files
with
82 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 78 additions & 12 deletions
90
testng/src/test/java/io/cucumber/testng/AbstractTestNGCucumberTestsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,111 @@ | ||
package io.cucumber.testng; | ||
|
||
import org.testng.Assert; | ||
import org.testng.IInvokedMethod; | ||
import org.testng.IInvokedMethodListener; | ||
import org.testng.ITestNGMethod; | ||
import org.testng.ITestResult; | ||
import org.testng.TestNG; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.frequency; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
@Test | ||
public final class AbstractTestNGCucumberTestsTest { | ||
|
||
private List<String> invokedConfigurationMethodNames; | ||
private List<String> invokedTestMethodNames; | ||
private final InvokedMethodListener icml = new InvokedMethodListener(); | ||
|
||
@BeforeClass(alwaysRun = true) | ||
public void setUp() { | ||
InvokedMethodListener icml = new InvokedMethodListener(); | ||
|
||
TestNG testNG = new TestNG(); | ||
testNG.addListener(icml); | ||
testNG.setGroups("cucumber"); | ||
testNG.setTestClasses(new Class[] { RunFeatureWithThreeScenariosTest.class }); | ||
testNG.setTestClasses(new Class[]{RunFeatureWithThreeScenariosTest.class}); | ||
testNG.run(); | ||
invokedConfigurationMethodNames = icml.getInvokedConfigurationMethodNames(); | ||
invokedTestMethodNames = icml.getInvokedTestMethodNames(); | ||
} | ||
|
||
@Test | ||
public void setUpClassIsInvoked() { | ||
Assert.assertTrue(invokedConfigurationMethodNames.contains("setUpClass"), "setUpClass must be invoked"); | ||
assertTrue(icml.getInvokedTestMethods().stream() | ||
.filter(IInvokedMethod::isConfigurationMethod) | ||
.map(IInvokedMethod::getTestMethod) | ||
.map(ITestNGMethod::getMethodName) | ||
.anyMatch("setUpClass"::equals), "setUpClass() must be invoked"); | ||
} | ||
|
||
@Test | ||
public void tearDownClassIsInvoked() { | ||
Assert.assertTrue(invokedConfigurationMethodNames.contains("tearDownClass"), "tearDownClass must be invoked"); | ||
assertTrue(icml.getInvokedTestMethods().stream() | ||
.filter(IInvokedMethod::isConfigurationMethod) | ||
.map(IInvokedMethod::getTestMethod) | ||
.map(ITestNGMethod::getMethodName) | ||
.anyMatch("tearDownClass"::equals), "tearDownClass() must be invoked"); | ||
} | ||
|
||
@Test | ||
public void runScenarioIsInvokedThreeTimes() { | ||
Assert.assertEquals(Collections.frequency(invokedTestMethodNames, "runScenario"), 3, | ||
"runScenario() must be invoked three times"); | ||
List<String> invokedTestMethodNames = icml.getInvokedTestMethods().stream() | ||
.filter(IInvokedMethod::isTestMethod) | ||
.map(IInvokedMethod::getTestMethod) | ||
.map(ITestNGMethod::getMethodName) | ||
.collect(Collectors.toList()); | ||
|
||
assertEquals(frequency(invokedTestMethodNames, "runScenario"), 3, | ||
"runScenario() must be invoked three times"); | ||
} | ||
|
||
@Test | ||
public void providesPickleWrapperAsFirstArgumentWithQuotedStringRepresentation() { | ||
List<String> parameters = icml.getInvokedTestMethods().stream() | ||
.filter(IInvokedMethod::isTestMethod) | ||
.map(IInvokedMethod::getTestResult) | ||
.map(ITestResult::getParameters) | ||
.map(objects -> objects[0]) | ||
.map(o -> (PickleWrapper) o) | ||
.map(Objects::toString) | ||
.collect(Collectors.toList()); | ||
|
||
assertEquals(parameters, asList("\"SC1\"", "\"SC2\"", "\"SC3\"")); | ||
} | ||
|
||
@Test | ||
public void providesFeatureWrapperAsSecondArgumentWithQuotedStringRepresentation() { | ||
List<String> featureNames = icml.getInvokedTestMethods().stream() | ||
.filter(IInvokedMethod::isTestMethod) | ||
.map(IInvokedMethod::getTestResult) | ||
.map(ITestResult::getParameters) | ||
.map(objects -> objects[1]) | ||
.map(o -> (FeatureWrapper) o) | ||
.map(Objects::toString) | ||
.collect(Collectors.toList()); | ||
|
||
assertEquals(frequency(featureNames, "\"A feature containing 3 scenarios\""), 3); | ||
} | ||
|
||
private static final class InvokedMethodListener implements IInvokedMethodListener { | ||
|
||
private final List<IInvokedMethod> invokedTestMethods = new ArrayList<>(); | ||
|
||
@Override | ||
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { | ||
} | ||
|
||
@Override | ||
public void afterInvocation(IInvokedMethod method, ITestResult testResult) { | ||
invokedTestMethods.add(method); | ||
} | ||
|
||
public List<IInvokedMethod> getInvokedTestMethods() { | ||
return invokedTestMethods; | ||
} | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
testng/src/test/java/io/cucumber/testng/InvokedMethodListener.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters