Getting Started
This is a hands-on tutorial for automating BDD scenarios using various BDD automation tools such as Cucumber and SpecFlow. By completing this tutorial you will have practice using all the meaningful features of these tools and confidence in your ability to apply them to real-world projects.
Business Concept
You will be developing a new social media app - with some similarities to Twitter - called Shouty. Users of the app will be able to ’shout’ - and will be ’heard’ by other users who are within 1000 meters of the shouter.
Shouty will initially support the following use case:
- Local Business Promotions e.g. "Half price coffee at Barney’s Café until 12 today"
The target platform is GPS-enabled smartphones.
Functional Requirements:
- Shouts should be text only - limited to 2000 characters
- The range of shouts should be 1000m
User Story:
As a business owner I want Shouty users within range to receive my promotional shouts So that I can generate more business
Here's a short video overview of Shouty
1. Select your programming language
- C#
- JavaScript
- Go
What you'll need:
- Visual Studio 2022, Visual Studio 2019, or Visual Studio 2017 (Community, Professional or Enterprise edition)
- .NET Core v3.1 (alternatively
TargetFrameworkin the.csprojfiles can be changed tonet6.0) - SpecFlow extension for Visual Studio
We recommend:
- Visual Studio 2022
What you'll need:
- Node.js version 16.14 or above
npm(installed automatically with Node.js)
You don’t need to install Cucumber or a test framework globally — everything is already configured in the project’s package.json.
node -v
npm -v
We recommend:
Go 1.21.3 or above
go version
This project uses godog v0.13.0 to run the tests.
2. Get the code
- C#
- JavaScript
- Go
Clone the Shouty project from https://github.com/cucumber-examples/shouty.net and open it in Visual Studio.
Clone the Shouty project from https://github.com/ryan-mars/shouty.js and open it in your
favourite editor or IDE.
npm install
This will install Cucumber.js, the assertion library, and the test framework used for the programmer tests.
This workshop uses plain JavaScript for all examples so everyone can follow the same path.
If you're already comfortable with TypeScript and Cucumber.js, you are welcome to:
- write your step definitions in
.tsinstead of.js - keep feature files exactly the same
- configure Cucumber to run using
ts-nodeor compile your step definitions before running
A typical setup looks like:
npm install --save-dev typescript ts-node @types/node
npx tsc --init
Modify the Cucumber configuration cucumber.js to load TypeScript, for example:
export default {
default: {
loader: ['ts-node/esm'],
import: ['features/**/*.ts'],
// ... other config
}
}
If that sounds unfamiliar, stick with JavaScript for this workshop — it keeps the focus on BDD, not tooling.
Clone or Download ZIP of the lastest Shouty project from https://github.com/bdd-champions/shouty-go and open it in your editor of choice.
If dependency installation hangs or fails, your corporate proxy is the most likely culprit. Disconnect from your work VPN and try again. You should only need to do this once.
There is no legitimate reason to change any project configuration or dependency versions to make this project run. If installation or execution isn’t working, tell the instructor immediately so we can diagnose it before you go down a rabbit hole.
3. Run the Tests
- C#
- JavaScript
- Go
- Open the
Shouty.NET.slnfile in Visual Studio - Select
Test>Run>All Testsfrom the menu, or pressCTRL-R, A
Run the tests with:
npm run test
This will run both the mocha (unit) and Cucumber tests.
go test
4. Inspect the output
- C#
- JavaScript
- Go
If you see some tests passing and some tests failing, you're good to go. 👍
If you see some tests passing and some tests failing, you're good to go. 👍
Mocha's output should look like this:
1 passing
1 failing
Cucumber's output should look like this:
2 scenarios (1 failed, 1 passed)
8 steps (1 failed, 7 passed)
If you see some tests passing and some tests failing, you're good to go. 👍