mercredi 14 juin 2017

Is it acceptable to include non-step methods in step definition classes?

Commonly, one tries to keep step definition classes as simple as possible and offload most of the business logic into object models. As a rule of thumb, we try limit the methods in step definition classes to binding step definition methods.

However, in some cases, multiple step definitions use similar code. One approach would be to extract this code in a new method within the same step definition class. For example:

[When(".....")]
public void WhenX() {
   // Do custom logic
   commonMethod():
}

[When(".....")] 
public void WhenY() {
   // Do custom logic
   commonMethod():
}

public void commonMethod() {
   // Common code
}

Another approach would be to move this code to a helper class. However, seeing as this code is only used within a single class, it might make more sense to bind it's scope to the respective class.

Aucun commentaire:

Enregistrer un commentaire