This is a port of Shouty to Python and Behave.
The original Shouty is a Cucumber open source training exercise that I first learned from Seb Rose. Thanks, Seb!
Shouty is a social networking application for short physical distances. When someone shouts, only people within 1000m can hear it.
Shouty doesn't exist yet—you will implement it yourself!
That is, if you're attending an awesome course on technical agility.
- A Python IDE (e.g. PyCharm)
- Python 3
- Behave support for your IDE (It's built-in to PyCharm)
Git:
git clone https://github.com/rkasper/shouty-python.git
Or simply download a zip and expand it into a directory on your computer.
In PyCharm
File > Open
Then browse to the directory where you downloaded shouty-python
and open the directory. The project should now load.
Type: pip install -r requirements.txt
On Mac or Linux:
- In PyCharm:
- Right-click the file
test-all.sh
> Run 'test-all.sh'
- Right-click the file
- Or in a terminal:
- Type:
./test-all.sh
- Type:
On Windows:
- In PyCharm:
- Right-click the file
test-all.bat
> Run 'test-all.bat'
- Right-click the file
- Or in a terminal:
- Type:
cmd.exe /c test-all.bat
- Type:
You should expect to see a couple of tests failing. If so, you're ready to roll!
The following exercises are adapted from the "BDD Workbook" by Seb Rose. We've included them here to guide you through the Shouty kata.
-
Take a look at the project and try to work out what each part is doing. Look at the following diagram and decide where each file in the project belongs. Write the file names here:
- Feature files: ________________________________________________
- Step Definition files: ________________________________________________
- Programmer test files: ________________________________________________
- Your app: ________________________________________________
-
Are there any files whose reason for existing is not clear? Which ones? Your answer: ________________________________________________
-
The feature file contains scenarios made up of steps. Each step causes Behave to look for a Python step definition to run. How does Behave decide which step definition to run for each step? Your answer: ________________________________________________
-
How does Behave decide which scenarios to run? Your answer: ________________________________________________
-
Run all the programmer tests and Behave scenarios.
-
You should see a mixture of passing and failing scenarios and tests. Note down:
- The name of a passing scenario: ________________________________________________
- The name of a failing scenario: ________________________________________________
- The name of a passing programmer test: ________________________________________________
- The name of a failing programmer test: ________________________________________________
-
How would you explain to your product owner what is wrong with Shouty, based on what you see in the test results? Your answer: ________________________________________________
-
Write the production code that will make the failing programmer test pass. You should not need to edit the feature file, the step definition file, or the programmer test file.
HINT: There's a commented out line of code in the Coordinate file that will get the test passing.
-
Run all the tests again. Both programmer tests should be passing, but one of the scenarios should still be failing.
-
Does the code you have just uncommented look like a complete solution? Your answer: ________________________________________________
-
Open the programmer test file and uncomment the programmer test that is commented out. Run all the tests again.
-
Which programmer test(s) are failing? Which scenario(s) are failing? Your answer: ________________________________________________
-
Can you see what changes you have to make to get the new programmer test to pass?
HINT: Use Pythagoras' theorem.
-
Keep working and running all the tests until you see all the programmer tests, steps, and scenarios pass.
We’ve just moved into new territory in the BDD cycle diagram. Look at the diagram again. Where are we now? What do we need to do next? Your answer: ________________________________________________
-
Look at the Gherkin expressions for Sean and Lucy's positions:
Lucy is at {xCoord:d}, {yCoord:d}
andSean is at {xCoord:d}, {yCoord:d}
. They're almost identical except for the person's name. -
Replace the person's name in the Gherkin expression with an output parameter so that the person's name is also passed to the step definition as an argument. Use
{name}
as the output parameter:{name} is at {xCoord:d}, {yCoord:d}
-
Update the step definition method to accept the new parameter. What type should the new parameter be? What's a good name for it?
-
Replace the hard-coded name in the body of the step definition method with the new parameter.
-
Run Behave. Did you get an AmbiguousStepDefinitionsException? Why? What do you need to do to fix it? Your answer: ________________________________________________
-
Run Behave again and check everything is still working as before.
This README and the included exercises are based on:
- The original Shouty kata by Cucumber Ltd.
- The BDD Workbook by Seb Rose
These materials have been adapted for use with the Python version of Shouty.