Cucumber is a BDD tool that supports Outside-in development by running plain text features or user stories as acceptance tests.
Let’s create our first feature. The anatomy of a feature is the following:
1 2 3 4
Notice how a feature includes who, what and most importantly: why.
1 2 3 4
There will be many scenarios accompanying a feature. Scenarios will follow the four stages of testing: setup, exercise, verify and teardown. A simple scenario looks like this:
1 2 3
Givenstep is where you set up the context of your scenario. Every scenario starts with a blank slate, so it is important to create a state in your application for example by creating data in the database, or by navigating to a specific page.
Whenstep is where you exercise the application in order to accomplish what needs testing. This is usually where you might fill in forms, press buttons, click links, or otherwise interact with the system in some way.
Thenstep is where you verify the result, and it’s where we check that the correct pages are rendered, that we see a success or error message, or anything that could help us verify that the prior action was successful.
- The teardown, is taken care of by cucumber automatically.
1 2 3 4 5
1 2 3 4 5 6 7 8 9
We can also test a user attempting to sign up without filling in all the fields:
1 2 3 4 5 6 7
cucumber --tags @billing --tags @important -> Runs the first scenario (Scenarios with @important AND @billing)
cucumber --tags @billing,@important -> Runs both scenarios (Scenarios with @important OR @billing)