Search code examples
pythontddpython-behave

TDD Implementing Step Definitions derived from Behave (Python)


Where do I put Behave's implementation code so that it will not fail Behave's tests? Further do I need to import anything or put any code in so the code I write is linked to the feature file.

Here an excerpt from my feature file \steps\main.feature ...

Feature: Main program
    Program allows users to create create and view development logs 

Scenario: User requests development logs for a particular user
    Given user has requested development logs for a given user
    Then the development logs for that user will show

And here are the implementation suggestions (that come from running Behave):

@given(u'user has requested development logs for a given user')
def step_impl(context):
    raise NotImplementedError(u'STEP: Given user has requested development logs for a given user')

@then(u'the development logs for that user will show')
def step_impl(context):
    raise NotImplementedError(u'STEP: Then the development logs for that user will show')

I realise this is really basic information but nothing in the documentation covers this and although there are lots of tutorial on Google none of them cover this. I assume it is just too basic.


Solution

  • The answer was to this was threefold:

    1. I was raising a not implemented error so the test failed.

    2. At the top of my Python file I needed to include from behave import *.

    3. My Python file needed to be a directory called steps.

    I worked this out myself by trial and error after looking at the answer to Python TDD directory structure.