docs
docs copied to clipboard
Updating Scenario hooks examples to be more like a SSCCE
The examples given in the API documentation are a bit too minimal, and they had me digging around for examples elsewhere, i.e. in the Scenario hooks page:
Before Before hooks run before the first step of each scenario.
Annotated method style:
@Before
public void doSomethingBefore() {
}
Lambda style:
Before(() -> {
});`
These are the examples given but the actual implementation requires a bit more, at least in the lambda case:
import io.cucumber.java8.En;
public class HooksExample implements En{
public HooksExample() {
Before(() -> {
System.out.println("In before hook.");
});
}
}
It doesn't mention anywhere on the page about implementing "En", or that a class constructor is needed for a working example. I would make a change request, but I am not sure on the styling, should there be a full example in each case? or just one at the top.
Thanks for reading.
Hi @Brice1994 - thanks for pointing that out. I would love better examples, if you are willing to start a PR for that. I'd prefer the examples to be consistent, so if you don't mind updating all the examples in this section, I'd be very grateful!
Ok, just a couple questions before I move on with it,
-
I see the hooks can be done in multiple languages, I am assuming I should just write the examples in English, but should I add any additional notes about other languages?
-
After digging I have found you can implement the Before, After, etc. in a class constructor or just a method, should I include both? or will 1 be fine?
Ad 1. Yes, please examples in English. A small note about other languages would be nice, if it doesn't create any confusion (i.e. it might lead to having to explain how to use cucumber with other languages, which may or may not be a separate PR. Idk)
Ad 2. Not sure what we have now, or whether we recommend one over the other. @mpkorstanje might know?
The annotated method has my preference. To avoid making the java doc overly complex I'd focus on cucumber-java and so I'd leave out the lambdas all together.