使用 python 实践 BDD

Python 有哪些最先进的框架和工具可用于实践行为驱动开发?特别是找到类似的工具,如 rspec 和摩卡的红宝石将是伟大的。

46322 次浏览

我可能完全没有抓住要点,但是我对 BDD 原始文件保留的是,BDD 只是 TDD的重新打包,以强调一些最佳实践。

如果我的解释是正确的,您可以通过在任何 XUnit实现中重命名方法来获得 BDD 框架。因此,只要继续使用标准库的 团结一致就可以了。

编辑: 一个快速谷歌出现在 奶酪店行为模块。进一步的 寻找为 BDD 有没有发现其他任何东西。

伊恩 · 比金建议使用 Doctest进行行为驱动设计:

我个人倾向于在行为驱动的设计风格中使用 鼻子空白空间模拟。具体来说,规格 插件的鼻子是优秀的 BDD。

Pyccuracy 项目致力于为 Python 中的 bDD 提供一个领域特定语言。

与在 API 级别工作的 doctest 不同,doctest 对加载网页和提交表单等高级操作进行编码。我还没用过,不过看起来很有希望如果你想要的是这个的话。

我非常喜欢 准确无误。这些天我在一个中型项目上实施它。

莴苣的意思是作为蟒蛇的一个类似黄瓜的工具: http://lettuce.it/

你可以在 github.com/gabrielfalcao/lettuce 找到源头

我建议您使用为帮助程序员实践 BDD 和 TDD 而开发的一组工具。该工具集由 派克蛋糕幽灵云鲁迪布里奥应该-dsl组成。

Should-DSL 将给您类似于 RSpec 的期望。使用 RSpec 期望 API 可以做的所有事情,should-dsl 也可以做。你可以拿 来自 Github 的最新版本

SpecLoud 帮助您运行类似 BDD 的单元测试

pip install specloud

Ludibrio 是一个用于测试替身(Mocks,Stubs 和 Dummies)的库

pip install ludibrio

PyCukes是 BDD 的主要工具,它会运行场景等等,

pip install pycukes

更多信息请阅读 派派上的工具文档。

很棒的帖子和答案。只是想更新,以包括 清爽在这个列表中,因为我读到 Pycukes 是停止。一个关于使用 BDD 和 Django 的好帖子是 给你

试试 派斯克斯。使测试易于阅读并在开发过程中不断运行是我创建这个项目的两个主要目标。

测试代码:

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)

我真的推荐 规矩点

我开始使用莴苣为 Python 寻找一个克隆黄瓜,但发现它是一个设计非常笨拙的复制品。非常平淡无奇。

然后我发现了表现,并且真的很高兴与它。

可以将 “当然”用于表达式断言(就像在 RSpec 中一样)