Take a look around
1. Get familiar with the project​
Now that you've cloned the Shouty project let's have a look around. There are only a few files here. Use the following diagram to help you decide what each file in the project is doing.
Try to match the files in the project to the shapes on the diagram.
- Feature File: Where we write our Given/When/Then scenarios.
- Step Definitions: Test code that connects to our Gherkin scenarios.
- Application Code: The heart of our project, the business logic.
- Unit Tests: Programmer tests that verify our code.
2. Answer the questions​
Question #1​
Which files correspond to the shapes on the diagram?
Show answer
- C#
- JavaScript
- Go
| Key Piece | Location |
|---|---|
| Application Code | Shouty.cs |
| Unit Tests | ShoutyTest.cs |
| Feature File | shout.feature |
| Step Definitions | ShoutSteps.cs |
| File. | Location |
|---|---|
| Feature File | features/hear_shout.feature |
| Step Definitions | features/step-definitions/shout_steps.js |
| Application Code | lib/shouty.js lib/coordinate.js |
| Unit Tests | test/coordinate.test.js |
| File. | Location |
|---|---|
| Feature File | hear_shout.feature |
| Step Definitions | godog_test.go |
| Application Code | shouty.go coordinate.go |
| Unit Tests | coordinate_test.go |
Question #2​
The feature file contains scenarios made up of steps. Each step causes SpecFlow to look for a matching Loading... step definition to run. How does SpecFlow decide which step definition to run for each step?
Show answer
- C#
- JavaScript
- Go
Step-definitions are denoted by C# attributes:
[Given(@"Lucy is at {int}, {int}")]
In JavaScript, step definitions are created using Cucumber.js functions like Given, When, and Then, each taking two arguments:
- A Cucumber Expression (or regex) that describes the text of the Gherkin step
- A JavaScript function that Cucumber will execute when the step matches
For example:
Given('Lucy is at {int}, {int}', function (x, y) {
// ...
}
Here's what this means:
Given(...)tells Cucumber this is a Given step definition'Lucy is at {int}, {int}'is a Cucumber Expression{int}captures numbers from the Gherkin text- those captured numbers become the parameters to the function
function (x, y)is the code that runs when the step matches- the extracted integers are passed in as
xandy
- the extracted integers are passed in as
A Gherkin step like:
Given Lucy is at 0, 0
matches this definition because:
- The literal parts (
Lucy is at) match exactly - The
{int}placeholders match0and0 - Cucumber binds
x = 0,y = 0and executes the function
Step definitions are denoted by Go function names and are registered with the godog test runner:
//...
sc.Step(`^Lucy is at (\d+), (\d+)$`, lucyIsAt)
//...
func lucyIsAt(x, y int) {
//...
}
Which match steps in the Gherkin like:
Given Lucy is at 0, 0
3. Discuss​
Are there any files whose reason for existing is not clear? Which ones?