Cucumbers: when to use tags / hooks against the background

I was wondering if there is a good argument for or against using a background in a cucumber compared to using tags and hooks.

Having a registered user before the start of the test may look like this:

Background: Given that I am logged in Scenario: Lorem ipsum sit amet dolor [...] 

or like this:

 @login Scenario: Lorem ipsum sit amet dolor [...] 

+

 before(@login) do visit('/admin/login/testuser') end 

Any idea when you prefer each other?

+8
ruby cucumber gherkin
source share
2 answers

Background is useful when you provide a general, user-readable (non-technical) background for your scenario. It should be used if you want to explicitly indicate this initialization in the text of your function.

But sometimes the logic of the U-turn (and setting) is implementation details and is implemented in Before , After or Around intercepts (because the reader of your specification does not need to know about these technical things).

Summary: use "Background" if you want to tell the reader about your background assumptions and use hooks when the background is implementation details.

In your example, the background is the best choice.

+9
source share

Definitely the first one (IMHO), as it captures everything in the universally readable Gherkin properties file. Tags only really help the runner - this is the level of implementation. What you describe here is part of the description of what is happening.

+4
source share

All Articles