From bc7a54be347bb52c40927b0cb48716d647bb0ff3 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Thu, 14 Nov 2019 09:04:30 +0100 Subject: [PATCH] BDD iteration #5 --- testing/bdd_iteration_5/accumulator.go | 9 +++++ testing/bdd_iteration_5/accumulator_test.go | 35 +++++++++++++++++++ .../features/accumulator.feature | 14 ++++++++ testing/bdd_iteration_5/results.txt | 31 ++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 testing/bdd_iteration_5/accumulator.go create mode 100644 testing/bdd_iteration_5/accumulator_test.go create mode 100644 testing/bdd_iteration_5/features/accumulator.feature create mode 100644 testing/bdd_iteration_5/results.txt diff --git a/testing/bdd_iteration_5/accumulator.go b/testing/bdd_iteration_5/accumulator.go new file mode 100644 index 0000000..d807c36 --- /dev/null +++ b/testing/bdd_iteration_5/accumulator.go @@ -0,0 +1,9 @@ +package accumulator + +type acc struct { + value int +} + +func (a *acc) accumulate(x int) { + a.value += x +} diff --git a/testing/bdd_iteration_5/accumulator_test.go b/testing/bdd_iteration_5/accumulator_test.go new file mode 100644 index 0000000..de6297a --- /dev/null +++ b/testing/bdd_iteration_5/accumulator_test.go @@ -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{} + }) +} diff --git a/testing/bdd_iteration_5/features/accumulator.feature b/testing/bdd_iteration_5/features/accumulator.feature new file mode 100644 index 0000000..e6ee205 --- /dev/null +++ b/testing/bdd_iteration_5/features/accumulator.feature @@ -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 to accumulator + Then the accumulated result should be + + Examples: + |amount|accumulated| + | 0 | 0 | + | 1 | 1 | + | 1 | 2 | + | 10 | 12 | diff --git a/testing/bdd_iteration_5/results.txt b/testing/bdd_iteration_5/results.txt new file mode 100644 index 0000000..6848a65 --- /dev/null +++ b/testing/bdd_iteration_5/results.txt @@ -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 to accumulator # accumulator_test.go:16 -> iAddToAccumulator + Then the accumulated result should be # 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