Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StepDefinitions should have at least one assert to call it as BDD test #80

Open
nagkumar opened this issue Apr 17, 2023 · 2 comments
Open

Comments

@nagkumar
Copy link

https://github.com/cucumber/cucumber-java-skeleton/blob/main/gradle/src/test/java/io/cucumber/skeleton/StepDefinitions.java

any test should have assert to make it clear what it is testing

image

@jkronegg
Copy link

I agree that "Then" step definitions should have at least one assert. But asserts should be optional for "Given" and "When" step definitions:

  • "Given" step definitions defines the testing context : you could use assert to ensure your testing context is coherent (e.g. no negative number of cukes)
  • "Then" step definitions define some action to do on the testing context : you could use assert to ensure your testing context is coherent (e.g. number of cukes has been defined)

So the @given "I have {int} cukes in my belly" example should be replaced with a @then step definition to make the issue more coherent.

By the way, it is true that this @given example is not very good as it creates a Belly but this object instance is automatically deleted by the JVM when the method ends, so it cannot be used in another step definition (the line 8 Belly belly = new Belly(); should be defined as a field to do so).

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Apr 17, 2023

You are looking at an intentionally incomplete project. The When and Then steps are present in the scenario:

Feature: Belly
Scenario: a few cukes
Given I have 42 cukes in my belly
When I wait 1 hour
Then my belly should growl

And this example project was written using a test driven approach. So just enough code has been written to get the tests running and failing. When run Cucumber will complain about two missing step definitions. You can add those and then incrementally implement the scenario.

This is great for people who are learning TDD, but probably less useful as a minimal working example. Please do feel free to workshop a better but still minimal example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants