【发布时间】:2010-09-18 21:13:20
【问题描述】:
有哪些最先进的框架和工具可用于 python 实践行为驱动开发?尤其是为 ruby 找到类似于 rspec 和 mocha 的工具会很棒。
【问题讨论】:
-
Flowp "允许用最少的魔法以 RSpec BDD 风格编写测试"。
-
只有在 SO 上,信息丰富才等于“没有建设性”。
有哪些最先进的框架和工具可用于 python 实践行为驱动开发?尤其是为 ruby 找到类似于 rspec 和 mocha 的工具会很棒。
【问题讨论】:
Ian Bicking 建议使用 doctest 进行行为驱动设计:
我个人倾向于在行为驱动的设计风格中使用nose 和voidspace mock。具体来说,nose 的规范 plugin 非常适合 BDD。
【讨论】:
我建议你使用一套工具来帮助程序员实践 BDD 和 TDD。该工具集由:pycukes、specloud、ludibrio 和should-dsl 组成。
Should-DSL 会给你类似 RSpec 的期望。你可以用 RSpec 期望 API 做的所有事情,should-dsl 也可以。你可以抓住latestversion from Github。
SpecLoud 帮助您运行类似 BDD 的单元测试。您可以通过以下方式安装它
pip install specloud
Ludibrio 是一个用于测试替身(Mocks、Stubs 和 Dummies)的库。通过
安装它pip install ludibrio
而PyCukes是BDD的主要工具。它将运行场景等。再次,
pip install pycukes
有关更多信息,请阅读PyPi 上的工具文档。
【讨论】:
试试pyspecs。使测试易于阅读和发展过程中不断磨合中创建这个项目是我的两个主要目标。 P>
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)
【讨论】:
您可以使用"sure" 进行表达性断言(就像在 RSpec 中一样)
【讨论】:
【讨论】:
我非常喜欢Pyccuracy。这些天我正在一个中型项目上实施它。
【讨论】:
Lettuce的意思是成为python的类似黄瓜的工具:http://lettuce.it/
您可以在 github.com/gabrielfalcao/lettuce 获取源代码
【讨论】:
Pyccuracy 项目旨在为 Python 中的 BDD 提供特定领域的语言。
与在 API 级别工作的 doctest 不同,它对更高级别的操作进行编码,例如加载网页和提交表单。我没有使用过它,但如果你正在寻找它,它看起来很有希望。
【讨论】:
我可能完全没有抓住重点,但我对 original BDD paper 的保留是 BDD 只是重新包装了 TDD 以强调一些最佳实践。
如果我的解释是正确的,您可以通过在任何xUnit 实现中重命名方法来获得 BDD 框架。所以请继续使用标准库的unittest。
编辑:快速谷歌在Cheese Shop 中找到了Behaviour 模块。进一步 searching 对于 BDD 没有找到其他任何东西。
【讨论】: