Tools
Unit Testing
Unit tests: A single piece of code (usually an object or a function) is tested, isolated from other pieces
Integration tests: Multiple pieces are tested together, for example testing database access code against a test database
Acceptance tests (also called Functional tests): Automatic testing of the entire application, for example using a tool like Selenium to automatically run a browser.
BDD Vs TDD
BDD is behavior driven specification for cross-functional team collaboration
TDD is implementation driven
BDD Tools
The automation tools for python are available in various flavors for behavior driven development.
Cucumber
The cucumber is available for Java.
There are no "official" Cucumber ports supported by the Cucumber organisation. That's not to say there aren't good alternatives. Try one of these:
Behave
Welcome to behave documentation
Behave example
Behave Test Automation
Getting started with Behave
Getting Started
Install Behave
$ pip install behave
mkdir features
mkdir features/steps
# for studout logging
$ cat behave.ini
[behave]
stderr_capture=True
stdout_capture=yes
$ cat features/example.feature
# -- FILE: features/example.feature
Feature: Showing off behave
Scenario: Run a simple test
Given we have behave installed
When we implement input1 tests
Then behave will test them for us!
$ cat features/steps/inputdata.py
class InputData():
def __init__(self):
self.data = {}
self.data['input1'] = 1
$ cat features/steps/example_steps.py
# -- FILE: features/steps/example_steps.py
from __future__ import print_function
from behave import given, when, then, step
import inputdata
@given('we have behave installed')
def step_impl(context):
pass
@when('we implement {input2} tests')
def step_impl(context, input2): # -- NOTE: number is converted into integer
context.inputdata = inputdata.InputData()
print("Hellloooooooooooooooooooooooooooooooooooooooooooooooo")
print("input : " + input2)
iny = context.inputdata.data.get(str(input2))
print(str(iny))
number = iny
assert number > 1 or number == 0
context.tests_count = number
@then('behave will test them for us!')
def step_impl(context):
assert context.failed is False
assert context.tests_count >= 0
$ behave
Feature: Showing off behave # features/example.feature:2
Scenario: Run a simple test # features/example.feature:4
Given we have behave installed # features/steps/example_steps.py:12 0.000s
When we implement input1 tests # features/steps/example_steps.py:16 0.000s
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/behave/model.py", line 1456, in run
match.run(runner.context)
File "/usr/local/lib/python2.7/dist-packages/behave/model.py", line 1903, in run
self.func(context, *args, **kwargs)
File "features/steps/example_steps.py", line 24, in step_impl
assert number > 1 or number == 0
AssertionError
Captured stdout:
Hellloooooooooooooooooooooooooooooooooooooooooooooooo
input : input1
1
Then behave will test them for us! # None
Failing scenarios:
features/example.feature:4 Run a simple test
0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
1 step passed, 1 failed, 1 skipped, 0 undefined
Took 0m0.000s
Lettuce
Lettuce documentation
Radish
Radish getting started