Skip to content

Commit

Permalink
BDD iteration RedHatOfficial#5
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Nov 14, 2019
1 parent a298db4 commit bc7a54b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
9 changes: 9 additions & 0 deletions testing/bdd_iteration_5/accumulator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package accumulator

type acc struct {
value int
}

func (a *acc) accumulate(x int) {
a.value += x
}
35 changes: 35 additions & 0 deletions testing/bdd_iteration_5/accumulator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package accumulator

import (
"fmt"
"github.com/DATA-DOG/godog"
)

var testAccumulator *acc

func iHaveAnAccumulatorWith(initialValue int) error {
testAccumulator.value = initialValue
return nil
}

func iAddToAccumulator(value int) error {
testAccumulator.accumulate(value)
return nil
}

func theAccumulatedResultShouldBe(expected int) error {
if testAccumulator.value == expected {
return nil
}
return fmt.Errorf("Incorrect accumulator value %d", testAccumulator.value)
}

func FeatureContext(s *godog.Suite) {
s.Step(`^I have an accumulator with (-?\d+)$`, iHaveAnAccumulatorWith)
s.Step(`^I add (-?\d+) to accumulator$`, iAddToAccumulator)
s.Step(`^the accumulated result should be (-?\d+)$`, theAccumulatedResultShouldBe)

s.BeforeScenario(func(interface{}) {
testAccumulator = &acc{}
})
}
14 changes: 14 additions & 0 deletions testing/bdd_iteration_5/features/accumulator.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: simple accumulator checks
An accumulator must be able to add a number to its content

Scenario Outline: Accumulate multiple values
Given I have an accumulator with 0
When I add <amount> to accumulator
Then the accumulated result should be <accumulated>

Examples:
|amount|accumulated|
| 0 | 0 |
| 1 | 1 |
| 1 | 2 |
| 10 | 12 |
31 changes: 31 additions & 0 deletions testing/bdd_iteration_5/results.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: simple accumulator checks
An accumulator must be able to add a number to its content

Scenario Outline: Accumulate multiple values # features/accumulator.feature:4
Given I have an accumulator with 0 # accumulator_test.go:11 -> iHaveAnAccumulatorWith
When I add <amount> to accumulator # accumulator_test.go:16 -> iAddToAccumulator
Then the accumulated result should be <accumulated> # accumulator_test.go:20 -> theAccumulatedResultShouldBe

Examples:
| amount | accumulated |
| 0 | 0 |
| 1 | 1 |
| 1 | 2 |
Incorrect accumulator value 1
| 10 | 12 |
Incorrect accumulator value 10

--- Failed steps:

Scenario Outline: Accumulate multiple values # features/accumulator.feature:4
Then the accumulated result should be 2 # features/accumulator.feature:7
Error: Incorrect accumulator value 1

Scenario Outline: Accumulate multiple values # features/accumulator.feature:4
Then the accumulated result should be 12 # features/accumulator.feature:7
Error: Incorrect accumulator value 10


4 scenarios (2 passed, 2 failed)
12 steps (10 passed, 2 failed)
356.714µs

0 comments on commit bc7a54b

Please sign in to comment.