Skip to content

Instantly share code, notes, and snippets.

@sjparkinson sjparkinson/

Last active Mar 21, 2017
What would you like to do?
Code club on TDD & BDD.

Test Driven Development (TDD)

  1. Write a test
  2. Write your code so the tests pass
  3. Refactor your code so it isn't 💩
  4. GOTO 1

Behaviour-driven Development (BDD)

BDD tests are written in a language called Ghurkin. There are lots of tools and frameworks in almost every language that can process files written in Ghurkin.

For Python pytest-bdd looks OK, there is also behave.

Feature: Search
Scenario: Search for a term
Given I search for <search_term>
Then the first result should link to <url>
| search_term | url . |
| Financial Times | |
| Google | |
from pytest_bdd import scenario, given, when, then
import pytest
import requests
@scenario('duckduckgo.feature', 'Search for a term')
def test_search():
@given("I search for <search_term>")
def search_request(search_term):
return requests.get('' % search_term)
@then("the first result should link to <url>")
def assert_first_search_result_url(search_request, url):
assert search_request.status_code == 200
assert url in search_request.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.