-
-
Notifications
You must be signed in to change notification settings - Fork 2k
AbstractTestNGCucumberTests runs each feature as separate test #653
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
import org.testng.annotations.Test; | ||
import cucumber.runtime.model.CucumberFeature; | ||
import gherkin.formatter.model.Feature; | ||
import org.testng.annotations.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please avoid wildcard imports?
@aslakhellesoy WDYT? |
I think all those protected fields should be private. I don't buy the argument that someone perhaps maybe might want to subclass this class in the future, and if they do I'm not convinced protected fields are the way to go. protected fields have a tendency to introduce bugs when they are altered in a way that wasn't expected by the class that declares them. I'll take it for a spin when that's fixed. |
@ushkinaz Is it possible to squash last 4 commits? There are too many of them just for changes according to code review.
verify that there is nothing lost
and then
|
* No wildcards * TestNGCucumberRunnerTest rewritten to comply strict policy of code reviewers * Stricter members access
Sure it's possible. |
Thanks a lot. |
@ffbit, just in case it went unnoticed - commits are now squashed. |
Hi, @ushkinaz. [1] I think that the story of Batman is quite interesting, but those extra files and counting number of them in the test are a bit out of place. |
@brasmusson, |
@ffbit I actually did start to look at this PR a bit today, but so far not on the testing issues. Since it is scenarios and not features that have passed/failed status in Cucumber, ideally both features and scenarios should appear in the TestNG tree. I do not know enough about TestNG to tell if that is possible or not, this PR is a step forward anyway. The printing of snippets (and statistics) to help the user is removed. I think that the AbstractTestNGCucumberTest class should have a I think the way to track if a feature pass or fail without creating a new runtime everytime, is to run the runtime with a custom Reporter (similar to the https://github.com/cucumber/cucumber-jvm/blob/master/junit/src/main/java/cucumber/runtime/junit/JUnitReporter.java), but only implementing the Reporter interface. In addition to the Reporter interface something like the following method would be needed by the TestNGCucumberRunner:
I'll will look at the testing in a day or two. |
* @return returns two dimensional array of {@link CucumberFeatureWrapper} objects. | ||
*/ | ||
@DataProvider | ||
public Object[][] features() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The content of this method should be extracted to TestNGCucumberRunner to simplify if anyone wants to both want to use composition (like in https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator-testng/src/test/java/cucumber/examples/java/calculator/RunCukesByCompositionTest.java) and get result for each feature separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most important part already extracted. See cucumber.api.testng.TestNGCucumberRunner#getFeatures.
There is no reason to extract the whole method, because it uses package local CucumberFeatureWrapper, which has very specific purpose. That class, CucumberFeatureWrapper, imho should be inner to AbstractTestNGCucumberTests, but it was extracted by request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Cucumber TestNG module has two API:s. First the AbstractTestNGCucumberTest - subclass it, annotate with @CucumberOptions
, and go. Second it is the TestNGCucumberRunner which need to be used directly when having to let the runner class subclass some other class (for instance to inherit @BeforeClass/@AfterClass
methods), this possibility was added in #622, and is exemplified by https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator-testng/src/test/java/cucumber/examples/java/calculator/RunCukesByCompositionTest.java. When they use the option to run each feature as a separate TestNG test, such runner classes are basically copies of AbstractTestNGCucumberTest. To support this kind of runner as good as possible, AbstractTestNGCucumberTest is best to contain only one line methods.
To really endorse the practice of running each feature as a separate TestNG test, this PR could rewrite https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator-testng/src/test/java/cucumber/examples/java/calculator/RunCukesByCompositionTest.java using the new methods in TestNGCucumberRunner.
@ffbit, @ushkinaz The test The remaining actions on the PR that I see are: |
@brasmusson could you please give me a couple of days to make review for you. |
@ffbit Absolutely, take the time you need. |
Sorry, clicked on the wrong button when trying to comment (had to use old browser) |
Really sorry about duplicate comments and stuff, tried to comment form an environment where I was stuck on an outdated browser, that was a big mistake. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Previously AbstractTestNGCucumberTests reported all features as a single test, making it a little bit difficult to understand which feature have failed scenarios.
With this change AbstractTestNGCucumberTests uses TestNG data provider to generate separate tests for each feature.
Test output is much nicer, especially in IDE.
Compare old to new. Both are screenshots from IntelliJ Idea running java-calculator-testng example.
Exiting API of TestNGCucumberRunner is kept unchanged.