题
哪些是python用于练习行为驱动开发的最先进的框架和工具?特别是找到类似rspec和mocha的类似红宝石的工具会很棒。
解决方案
Ian Bicking 建议使用 doctest :
其他提示
生菜意味着成为一个类似黄瓜的python工具: http://lettuce.it/
您可以在github.com/gabrielfalcao/lettuce
获取来源我建议您使用一组工具来帮助程序员实施BDD和TDD。此工具集由以下内容组成: pycukes , specloud , ludibrio 和 should-dsl 。
Should-DSL 将为您提供类似RSpec的期望。您可以使用RSpec期望API执行的所有操作,ds-dsl也可以。您可以从Github获取 latestversion 。
SpecLoud 可帮助您运行类似BDD的单元测试。您可以通过执行
来安装它pip install specloud
Ludibrio 是一个测试双打(模拟,存根和傻瓜)的库。通过
安装pip install ludibrio
PyCukes 是BDD的主要工具。它将运行场景等。再次,
pip install pycukes
有关详细信息,请阅读 PyPi 上的工具文档。
您可以使用“确定”来表达断言(就像在RSpec中一样)
Pyccuracy项目旨在为Python中的BDD提供特定于域的语言。
与在API级别工作的doctest不同,它对更高级别的操作进行编码,例如加载网页和提交表单。我没有使用它,但如果你正在寻找它,它看起来有点大有希望。
我非常喜欢 Pyccuracy 。我这几天正在中型项目上实施它。
试用 pyspecs 。在开发过程中使测试易于阅读和持续运行是我创建该项目的两个主要目标。
测试代码:
from pyspecs import given, when, then, and_, the, this
with given.two_operands:
a = 2
b = 3
with when.supplied_to_the_add_function:
total = a + b
with then.the_total_should_be_mathmatically_correct:
the(total).should.equal(5)
with and_.the_total_should_be_greater_than_either_operand:
the(total).should.be_greater_than(a)
the(total).should.be_greater_than(b)
with when.supplied_to_the_subtract_function:
difference = b - a
with then.the_difference_should_be_mathmatically_correct:
the(difference).should.equal(1)
控制台输出:
# run_pyspecs.py
| • given two operands
| • when supplied to the add function
| • then the total should be mathmatically correct
| • and the total should be greater than either operand
| • when supplied to the subtract function
| • then the difference should be mathmatically correct
(ok) 6 passed (6 steps, 1 scenarios in 0.0002 seconds)
不隶属于 StackOverflow