docs icon indicating copy to clipboard operation
docs copied to clipboard

Updating Scenario hooks examples to be more like a SSCCE

Open Brice1994 opened this issue 5 years ago • 5 comments
trafficstars

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.

Brice1994 avatar Dec 02 '19 19:12 Brice1994

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!

mlvandijk avatar Dec 29 '19 09:12 mlvandijk

Ok, just a couple questions before I move on with it,

  1. 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?

  2. 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?

Brice1994 avatar Dec 31 '19 15:12 Brice1994

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)

mlvandijk avatar Jan 24 '20 10:01 mlvandijk

Ad 2. Not sure what we have now, or whether we recommend one over the other. @mpkorstanje might know?

mlvandijk avatar Jan 24 '20 10:01 mlvandijk

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.

mpkorstanje avatar Jan 24 '20 10:01 mpkorstanje