Skip to content

Cucumber Scala final output shows 0 failures even when a scenario fails #102

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

Closed
rhande-mdsol opened this issue Jul 8, 2020 · 12 comments · Fixed by cucumber/cucumber-jvm#2045
Labels
🐛 bug Defect / Bug
Milestone

Comments

@rhande-mdsol
Copy link

rhande-mdsol commented Jul 8, 2020

I have a cucumber test suite which has some tests

I run the tests using command

sbt "testOnly <cucumber_class_name>"

And one of the cucumber tests fail an assertion and console shows

Failed scenarios:
classpath:features/my_cucumber_scenario.feature:31# <my test description>

19 Scenarios (1 failed, 18 passed)
88 Steps (1 failed, 87 passed)sts 214s
3m18.224s

But in the end the console shows

Total 80, Failed 0, Errors 0, Passed 80

Since one of the tests failed, in the final output it should have shown
Failed 1 (Or something like that). But it is showing all passed instead due to which my build on travis is not failing.

How to solve this problem ? Is there a solution in cucumber ?

My dependencies are

"io.cucumber" % "cucumber-core" % "5.7.0",
"io.cucumber" % "cucumber-junit" % "5.7.0"
"io.cucumber" %% "cucumber-scala" % "5.7.0"

@gaeljw
Copy link
Member

gaeljw commented Jul 8, 2020

Hello @rhande-mdsol ,

Could it be that you have multiple scenarios with the same name (in the same file), or Scenario Outlines?

If so, this is is a known issue in sbt-junit interface:
sbt/junit-interface#84. See also #22

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Jul 8, 2020

Might be worth adding a work around to detect if sbt-junit is used and act accordingly. The project seems dead.

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Jul 8, 2020

Or ensure the names provided to the JUnit Description are always unique. That way sbt will also be able to handle identical features, scenarios, examples, ect. Shouldn't be too much of a burden if the #n suffix only shows up when necessary.

mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Jul 8, 2020
Individual examples do not have a unique name. And while a unique name is not
required by Junit, various integrations such as sbt-junit assume this the case.

By appending ` [#n]` to a scenario name it becomes unique again. So JUnit 4s
output becomes:

```
A feature with scenario outlines
  A scenario outline [#1]
  A scenario outline [#2]
  A scenario outline [#3]
  A scenario outline [#4]
```

The `[...]` come from JUnit 4s `Parameterized` runner which outputs similar
names. And the `#n` was taken from JUnit 5 which renders examples as:

```
A feature with scenario outlines
  A scenario outline
    With some other text
      Example #1
      Example #2
    With some text
     Example #1
     Example #2
```

Fixes: cucumber/cucumber-jvm-scala#102
@mpkorstanje
Copy link
Contributor

Would either of you mind checking if cucumber/cucumber-jvm#2045 solves the problem.

mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Jul 8, 2020
Individual examples do not have a unique name. And while a unique name is not
required by Junit, various integrations such as sbt-junit assume this the case.

By appending ` [#n]` to a scenario name it becomes unique again. So JUnit 4s
output becomes:

```
A feature with scenario outlines
  A scenario outline #1
  A scenario outline #2
  A scenario outline #3
  A scenario outline #4
```

The `#n` was taken from JUnit 5 which renders examples as:

```
A feature with scenario outlines
  A scenario outline
    With some other text
      Example #1
      Example #2
    With some text
     Example #1
     Example #2
```

Fixes: cucumber/cucumber-jvm-scala#102
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Jul 8, 2020
Individual examples do not have a unique name. And while a unique name is not
required by Junit, various integrations such as sbt-junit assume this the case.

By appending ` [#n]` to a scenario name it becomes unique again. So JUnit 4s
output becomes:

```
A feature with scenario outlines
  A scenario outline #1
  A scenario outline #2
  A scenario outline #3
  A scenario outline #4
```

The `#n` was taken from JUnit 5 which renders examples as:

```
A feature with scenario outlines
  A scenario outline
    With some other text
      Example #1
      Example #2
    With some text
     Example #1
     Example #2
```

Fixes: cucumber/cucumber-jvm-scala#102
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Jul 8, 2020
Individual examples do not have a unique name. And while a unique name is not
required by Junit, various integrations such as sbt-junit assume this the case.

By appending ` [#n]` to a scenario name it becomes unique again. So JUnit 4s
output becomes:

```
A feature with scenario outlines
  A scenario outline #1
  A scenario outline #2
  A scenario outline #3
  A scenario outline #4
```

The `#n` was taken from JUnit 5 which renders examples as:

```
A feature with scenario outlines
  A scenario outline
    With some other text
      Example #1
      Example #2
    With some text
     Example #1
     Example #2
```

Fixes: cucumber/cucumber-jvm-scala#102
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Jul 8, 2020
Individual examples do not have a unique name. And while a unique name is not
required by Junit, various integrations such as sbt-junit assume this the case.

By appending ` [#n]` to a scenario name it becomes unique again. So JUnit 4s
output becomes:

```
A feature with scenario outlines
  A scenario outline #1
  A scenario outline #2
  A scenario outline #3
  A scenario outline #4
```

The `#n` was taken from JUnit 5 which renders examples as:

```
A feature with scenario outlines
  A scenario outline
    With some other text
      Example #1
      Example #2
    With some text
     Example #1
     Example #2
```

Fixes: cucumber/cucumber-jvm-scala#102
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Jul 8, 2020
Individual examples do not have a unique name. And while a unique name is not
required by Junit, various integrations such as sbt-junit assume this the case.

By appending ` [#n]` to a scenario name it becomes unique again. So JUnit 4s
output becomes:

```
A feature with scenario outlines
  A scenario outline #1
  A scenario outline #2
  A scenario outline #3
  A scenario outline #4
```

The `#n` was taken from JUnit 5 which renders examples as:

```
A feature with scenario outlines
  A scenario outline
    With some other text
      Example #1
      Example #2
    With some text
     Example #1
     Example #2
```

Fixes: cucumber/cucumber-jvm-scala#102
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Jul 8, 2020
Individual examples do not have a unique name. And while a unique name is not
required by Junit, various integrations such as sbt-junit assume this the case.

By appending ` [#n]` to a scenario name it becomes unique again. So JUnit 4s
output becomes:

```
A feature with scenario outlines
  A scenario outline #1
  A scenario outline #2
  A scenario outline #3
  A scenario outline #4
```

The `#n` was taken from JUnit 5 which renders examples as:

```
A feature with scenario outlines
  A scenario outline
    With some other text
      Example #1
      Example #2
    With some text
     Example #1
     Example #2
```

Fixes: cucumber/cucumber-jvm-scala#102
@rhande-mdsol rhande-mdsol reopened this Jul 9, 2020
@rhande-mdsol
Copy link
Author

Sorry Closed by mistake.

@rhande-mdsol
Copy link
Author

rhande-mdsol commented Jul 9, 2020

@mpkorstanje I am using

"io.cucumber" % "cucumber-core" % "5.7.0",
"io.cucumber" % "cucumber-junit" % "5.7.0"
"io.cucumber" %% "cucumber-scala" % "5.7.0"

So it is cucumber scala. Your code in cucumber/cucumber-jvm#2045
seems to be Java code. Can I use it ?

I will try publishing your code and let you know

@gaeljw
Copy link
Member

gaeljw commented Jul 9, 2020

@rhande-mdsol Cucumber Scala is using Cucumber JVM which is the foundation for various Cucumber libraries targeting the JVM.

In this case, it's the project cucumber-junit that you could try to build on your own with the PR mentioned by @mpkorstanje and use in your project.

I will also try the PR on my side but probably later today.


@rhande-mdsol Do you confirm that your case is multiple scenarios with the same name in the same file, or using Scenario Outlines ?

@gaeljw gaeljw added the 🐛 bug Defect / Bug label Jul 9, 2020
@rhande-mdsol
Copy link
Author

rhande-mdsol commented Jul 9, 2020

@rhande-mdsol Cucumber Scala is using Cucumber JVM which is the foundation for various Cucumber libraries targeting the JVM.

In this case, it's the project cucumber-junit that you could try to build on your own with the PR mentioned by @mpkorstanje and use in your project.

I will also try the PR on my side but probably later today.

@rhande-mdsol Do you confirm that your case is multiple scenarios with the same name in the same file, or using Scenario Outlines ?

Hi @gaeljw ,

Yes, this problem happens when I have a Scenario Outline: and then have a table like structure in Examples: section. For me 3rd example actually failed, but final result showed all tests passed.
Also this happens when you have a Step with parameterized value and reuse the step in the same Feature file at multiple places.

For example :

Scenario 1 =>

Scenario:
Given I know "Java"
Then I teach "Java"

Scenario 2 =>

Scenario:
Given I know "Scala"
Then I teach "Scala"

If Scenario 2 fails here, the final result still shows all have passed.

I also tried failing a scenario without an outline (i.e. Scenario:) in this case final result shows failures properly.

Thanks

@gaeljw
Copy link
Member

gaeljw commented Jul 9, 2020

Thanks for confirming.

cucumber/cucumber-jvm#2045 should fix the issue then.
You just have to wait a bit for the next cucumber-junit release (you'll have to update to 6.x but the upgrade from 5.x to 6.x is pretty easy).

mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Jul 9, 2020
Individual examples do not have a unique name. And while a unique name is not
required by Junit, various integrations such as sbt-junit assume this the case.

By appending ` [#n]` to a scenario name it becomes unique again. So JUnit 4s
output becomes:

```
A feature with scenario outlines
  A scenario outline #1
  A scenario outline #2
  A scenario outline #3
  A scenario outline #4
```

The `#n` was taken from JUnit 5 which renders examples as:

```
A feature with scenario outlines
  A scenario outline
    With some other text
      Example #1
      Example #2
    With some text
     Example #1
     Example #2
```

Fixes: cucumber/cucumber-jvm-scala#102
@gaeljw gaeljw added this to the 6.2.2 milestone Jul 9, 2020
@rhande-mdsol
Copy link
Author

Thanks for fixing the problem. Now final result shows failure when there is a failure in scenario outline.

@ejaoua
Copy link

ejaoua commented May 26, 2023

Hi @rhande-mdsol ,
can you please share what was the plugin and/or correct syntax that you used to run one test of Cucumber :
sbt "testOnly <cucumber_class_name>".
I tried the following but it didn't work out sbt "testOnly *classpath:features/folder1/endpoint.feature
Thanks.

@gaeljw
Copy link
Member

gaeljw commented May 26, 2023

@ejaoua you might want to take it to Slack to discuss these kind of things, or open a new issue/discussion at least.

Short answer: I don't think that's possible this way. You have to run testOnly SomeClass where SomeClass targets only some features file.

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

Successfully merging a pull request may close this issue.

4 participants