Skip to content

Instantly share code, notes, and snippets.

@sjparkinson sjparkinson/02-tdd-bdd.md
Last active Mar 21, 2017

Embed
What would you like to do?
Code club on TDD & BDD.

Test Driven Development (TDD)

https://en.wikipedia.org/wiki/Test-driven_development#Test-driven_development_cycle

  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)

https://en.wikipedia.org/wiki/Behavior-driven_development#Behavioral_specifications

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 duckduckgo.com
Scenario: Search for a term
Given I search for <search_term>
Then the first result should link to <url>
Examples:
| search_term | url . |
| Financial Times | www.ft.com |
| Google | www.google.com |
from pytest_bdd import scenario, given, when, then
import pytest
import requests
@scenario('duckduckgo.feature', 'Search for a term')
def test_search():
pass
@given("I search for <search_term>")
def search_request(search_term):
return requests.get('https://duckduckgo.com/html/?q=%s' % 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.