How to write declarative Cucumber functions to describe CRUD operations?

I understand the difference between the imperative and declarative steps of a cucumber , but I have not seen real examples of this. I always feel that my function files are getting too verbose.

It seems that for each stage of the life cycle there should be a function of cucumber:

  • foobars/list_foobars.feature
  • foobars/create_foobar.feature
  • foobars/view_foobar.feature
  • foobars/edit_foobar.feature
  • foobars/delete_foobar.feature

In the only creation function, it seems that you want to specify the fields that can be entered, which ones are needed, what happens when you enter incorrect data, etc. I do not know a declarative way to do this. Of course, in the following functions, you simply say Given a foobar exists , and do not go through all the steps to create it.

How much detail will you tell about your application behavior? Can you give some examples of function files that you think are reasonably complete?

+7
source share
2 answers

I like it when people read cucumber tests, so assuming we have a story for editing foobar with invalid data, I need a script like:

 # foobars/edit_foobar.feature Feature: As a user, I want to edit a Foobar, so I can Baz Scenario: Validation Errors Given I am logged in as a user And a foobar exists And I edit the foobar with invalid data Then I should see validation errors 

I think that it captures what we want from history, without dealing with all the details about which fields to edit, which buttons to send, etc. It does not check all possible cases, but they should really be tested using unit tests (model tests that are installed for verification, and control tests install flash messages or request tests that serve errors).

Other scenarios are similar:

 Scenario: Successful Edit Given I am logged in as a user And a foobar exists And I edit the foobar with valid data Then I should see the valid data 

Some people will want to provide valid data as part of the test itself, but I personally prefer to delegate it to the step definitions to keep the scripts clean. You just need one example to make sure the golden case works, because again this is not the right place to check that all form fields are working (and this will become a maintenance headache if you specify each individual field).

+4
source

I think it might not be possible to test this at all using Cucumber, instead just make a comment in the Feature section.

Alternatively, you can do something like this:

 # categories.feature Scenario: Manage categories Given I want to manage categories When I <crud_type> a category Then I should be taken to the listing page Examples: | crud_type | | create | | edit | | delete | Scenario: View category Given I want to view a particular category When I click on a category in the category list Then I should see that category view page 
-one
source

All Articles