CXwudi / comp5903-easy-cucumber

A JVM Cucumber implementation that is easy to use. It is the enhanced "Cucumberized JUnit" of the original version from Alexei https://github.com/alexeikrumshyn/cucumberized-junit
0 stars 0 forks source link

[Bug]Error message is not accurate when a step definition is missing #8

Closed saurabhsjoshi closed 2 years ago

saurabhsjoshi commented 2 years ago

Describe the bug or Question When the framework is unable to match a statement from feature file to a step definition (most likely due to missing step def), the error message is not accurate as it refers to some other line in the feature file instead of the line that cause the issue.

(For bug report only) To Reproduce For example if I have following scenario:

Scenario: Row 89
    Given The game starts with 1 player
    And The player names are the following 'Player1'
    When 'Player1' gets 'GOLD' fortune card
    And 'Player1' rolls the following 'MONKEY,MONKEY,MONKEY,SWORD,SWORD,SWORD,DIAMOND,PARROT'
    And 'Player1' ends turn
    Then Player scores are the following 'Player1 400'

And for example, if I have not defined a step-def for the line And The player names are the following 'Player1' I see the following stack-trace:

scs.comp5903.cucumber.model.exception.EasyCucumberException: EZCU013: Step definition not found for: WhenStep(stepString='Player1' gets 'GOLD' fortune card). Are you sure you implemented this step definition? Or did you forget to make the method public?

    at scs.comp5903.cucumber.builder.JFeatureBuilder.lambda$mapAllStepsToStepDefMethods$0(JFeatureBuilder.java:89)
    at java.base/java.util.Optional.orElseThrow(Optional.java:403)
    at scs.comp5903.cucumber.builder.JFeatureBuilder.mapAllStepsToStepDefMethods(JFeatureBuilder.java:88)
    at scs.comp5903.cucumber.builder.JFeatureBuilder.build(JFeatureBuilder.java:46)
    at scs.comp5903.cucumber.EasyCucumber.build(EasyCucumber.java:147)
    at scs.comp5903.cucumber.EasyCucumber.build(EasyCucumber.java:68)

(If applicable) Stack Trace

logs

Pasted above

(If applicable) Screenshots If applicable, add screenshots to help explain your problem.

(For bug report only) Expected behavior The error message should mention Step definition not found for And The player names are the following 'Player1' instead of the line that is below that.

Environment (please complete the following information):

Anything else N/A

CXwudi commented 2 years ago

Interesting, I will look into that

CXwudi commented 2 years ago

LOL, what am I doing...

    while (!stepsCopy.isEmpty()) {
      var step = stepsCopy.poll();
      var matchResult = tryMatchStep(step, jStepDefMethodDetails).orElseThrow(
          () -> new EasyCucumberException(ErrorCode.EZCU013, "Step definition not found for: " + stepsCopy.get(0)
              + ". Are you sure you implemented this step definition? Or did you forget to make the method public?")
      );
      results.put(step, matchResult);
    }

it should not be stepsCopy.get(0) but step

Guess I will need another hot fix release 0.3.2, but seems it is not affecting the functionalities I will just pin this issue for a period of time and not bothering board casting another email