Reputation: 11
I'm completely new to Python and automated testing, so as a proof of concept I am testing a simple method that corrects certain misspellings of Cub Scout den names to their correct den name.
My feature file:
Feature: denConverter method
Scenario: Invalid Names
Given the den name xyz
When the denConverter method is run
Then denConverter should return None
Scenario Outline: Valid Names
Given the den name <initialName>
When the denConverter method is run
Then denConverter should return <endName>
Examples: Possible Entries
| initialName | endName |
| Wolf | Wolf |
| Wolves | Wolf |
| Lion | Lion |
| Tiger | Tiger |
| Bear | Bear |
| Webelos | Webelos |
| AoL | AoL |
| Arrowoflight | AoL |
| Arrowoflights | AoL |
| Bears | Bear |
My steps file:
from behave import *
from DenScheduler import denConverter
class DenName:
def __init__(self):
input_name = ""
output_name = ""
@given('the den name "{initialName}"')
def step_impl(context, initialName):
context.den_name = DenName()
context.den_name.input_name = initialName
pass
@given('the den name xyz')
def step_impl(context):
context.den_name = DenName()
context.den_name.input_name = "xyz"
pass
@when('the denConverter method is run')
def step_impl(context):
context.den_name.output_name = denConverter(context.den_name.input_name)
assert True is not False
@then('denConverter should return "{endName}"')
def step_impl(context, endName):
assert context.den_name.output_name == endName
@then('denConverter should return None')
def step_impl(context):
assert context.den_name.output_name == None
When I run behave, all of the tests in the Scenario Outline "Valid Names" fail like so:
Scenario Outline: Valid Names -- @1.1 Possible Entries # features/denConverter.feature:15
Given the den name Wolf # None
When the denConverter method is run # None
Then denConverter should return Wolf # None
@given(u'the den name Wolf')
def step_impl(context):
raise NotImplementedError(u'STEP: Given the den name Wolf')
@then(u'denConverter should return Wolf')
def step_impl(context):
raise NotImplementedError(u'STEP: Then denConverter should return Wolf')
I'm sure I'm missing something obvious, but I've been stuck on this for hours trying to look up what is going wrong. On that note, I notice that some examples use @given(u'given statement') while others use @given('given statement'), with no "u", and I'm not sure what the "u" is for. I've tried both with and without the "u".
Upvotes: 1
Views: 1718
Reputation: 1057
it's sometimes worth checking for capital letters that are easy to miss.
For example I had step:
@step(u'(?P<service_category>.*) service (?P<service_data_key>.*) has RAG Status (?P<exptected_status>.*)')
and the usage was:
And H.264 service <service_data_key> has RAG status HEALTHY
So Pycharm PRO gherkin code linked such step usage with its implementation easily.
But in reality there will be NotImplementedError thrown, because "Status" in step definition is upper case, and in the usage "status" is lower case
So worth checking for this root cause, I came here with this issue and only later found it out
Upvotes: 0
Reputation: 323
There are 2 options of solving that. Either by updating the gherkin and enclose your parameters with "" like:
Given the den name "xyz"
or by removing the same from decorator like:
@given('the den name {initialName}')
Generally Gherkin step name should match the name in decorated string. So the 2 below go together:
@given('the den name "{initialName}"')
Given the den name "xyz"
or the following two:
@given('the den name {initialName}')
Given the den name xyz
Usually we define parameters inside comment characters:"" and they are recognized as strings by default inside the method. It's also more clear for the reader of such feature to understand where are the boundaries of these parameters. Parameters placed withou "" signs can be recognized as digits if you enter a number like:
Given the den name 100
Which is useful when you work with some numbers.
Upvotes: 3