哪些是python用于练习行为驱动开发的最先进的框架和工具?特别是找到类似rspec和mocha的类似红宝石的工具会很棒。

有帮助吗?

解决方案

Ian Bicking 建议使用 doctest

我个人倾向于使用鼻子”和空洞模拟 。具体来说,规范插件非常适合BDD。

其他提示

生菜意味着成为一个类似黄瓜的python工具: http://lettuce.it/

您可以在github.com/gabrielfalcao/lettuce

获取来源

我真的建议表现

寻找Python的黄瓜克隆,我开始使用生菜,但发现它是一个非常笨拙设计的复制品。非常Unpythonic。

然后我发现了行为,并且对它非常满意。

我建议您使用一组工具来帮助程序员实施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 上的工具文档。

很棒的帖子和答案。我想更新以在此列表中包含 Freshen ,因为我读取了pycukes已停止使用。关于使用BDD和Django与Freshen的好帖子是这里

您可以使用“确定”来表达断言(就像在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)

我可能完全忽略了这一点,但我保留的原始BDD论文是BDD只是 TDD 重新包装,以强调一些最佳实践。

如果我的解释是正确的,您可以通过在任何中重命名方法来获得BDD框架。 xUnit 实施。所以请继续使用标准库的 unittest

编辑:快速谷歌在行为模块http://pypi.python.org/pypi“rel =”nofollow noreferrer“>奶酪店。进一步搜索 BDD,但没有找到任何其他内容。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top