1

I've tried with BDD and Cucumber to get the final number of tests ("Thens" or outcome steps) but we get the number of features, tags and scenarios only. I need the number of tests passed and failed but no solution yet.

How can I get the number of "Thens" in the final report?

Lunivore
  • 17,277
  • 4
  • 47
  • 92
  • Normally with Cucumber the scenarios *are* the tests, so the scenario count is the test count. What do you mean by "test"? Are you looking for the number of outcome ("Then") lines, or something like that? Is there a decision you're trying to make with that information? What reporter plugins / options have you tried? Please add a bit more detail so we can help you! – Lunivore Mar 22 '21 at 15:14
  • @Lunivore Each scenario content more than a one test ! what i need is to get the full number of tests generated during my projects. with cucumber there's no solution that's why i ask if there's any plugin to add or something to modify. – M Hedi NAGMAR Mar 22 '21 at 15:31
  • @Lunivore yes can i et the number of "Then" at my report ? – M Hedi NAGMAR Mar 22 '21 at 15:40
  • 1
    Please edit the question so that this is clear, and I will ask to reopen it. I don't think it should have been closed; this is not a duplicate of the one @peter-thomas flagged as you were getting a report (and you mentioned getting features, tags and scenarios so that much was clear to me), just not with the details you wanted. – Lunivore Mar 22 '21 at 16:16
  • 2
    reopened. all yours – Peter Thomas Mar 22 '21 at 16:25

1 Answers1

2

I think you can override Cucumber's formatter with one of your own using the --format flag. The documentation is here. You may alternatively be able to add your own custom formatter when constructing the Cucumber options; this blog shows how. Relevant snippet:

@RunWith(Cucumber.class)
@CucumberOptions(
    plugin = {"pretty",
        "json:target/report.json",
        "html:target/html",
        "config.CustomTagsFormatter:target/tags.txt"},
    features = "src/test/resources/feature")
public class TestRunner {}

You will have to do some clever programming to get the type of step, since Cucumber doesn't really differentiate between Given, When and Then. Take a look at what you get in the different events, though; the step_activated event should give you the full text of the step, including the starting keyword.

Bear in mind that some of the steps may start with "And" or "But" rather than "Then", so it isn't as simple as counting all the "Then" steps. I suggest turning a counter on for "Then" at the start of a step, and turning it off if you encounter a "Given" or "When".

I'm very curious as to why you need this, though! Any step - even Givens or Whens - could theoretically contain an assertion that might fail, and Thens could contain more than one.

Lunivore
  • 17,277
  • 4
  • 47
  • 92
  • Even with the steps counter can't get the real number of "Then" & "And" with cucumber. What i am searching for is to get my Karate report with the final number of tests applied as a count that's it. @PeterThomas – M Hedi NAGMAR Mar 24 '21 at 14:52
  • Try not just counting the steps, but count the steps beginning with "Then". For that, you'll need something custom; Cucumber doesn't give it to you. Cucumber recognizes that there are "steps" by their keywords (Given, When, Then, And, But) but doesn't care which they are. There is no way, other than parsing the text of the steps, to get the keywords. Why do you want this information? What are you doing with it? – Lunivore Mar 25 '21 at 00:39