问题:用python练习BDD [关闭]

python有哪些最先进的框架和工具可用于实践行为驱动开发?尤其是找到与rspec和mocha类似的工具来进行红宝石搜索将是很棒的。

Which are the most advanced frameworks and tools there are available for python for practicing Behavior Driven Development? Especially finding similar tools as rspec and mocha for ruby would be great.


回答 0

Ian Bicking建议将doctest用于行为驱动的设计:

我个人倾向于以行为驱动的设计风格使用鼻子空隙模拟。具体来说,鼻子的规范插件非常适合BDD。

Ian Bicking recommends using doctest for behavior driven design:

I personally tend to use nose and voidspace mock in a behavior driven design style. Specifically, the spec plugin for nose is excellent for BDD.


回答 1

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

您可以在github.com/gabrielfalcao/lettuce上获取源代码

Lettuce means to be a cucumber-like tool for python: http://lettuce.it/

You can grab the source at github.com/gabrielfalcao/lettuce


回答 2

我真的建议您表现良好

在寻找适用于Python的黄瓜克隆时,我开始使用生菜,但发现它是一个笨拙设计的副本。非常不合常规。

然后我发现了行为,并对此感到非常满意。

I really recommend behave.

Looking for a Cucumber clone for Python, I started using lettuce, but found it a pretty clumsily designed replica. Very Unpythonic.

Then I discovered behave, and have been really happy with it.


回答 3

我建议您使用开发的一组工具来帮助程序员进行BDD和TDD的实践。该工具集由pycukesspecloudludibrioshould-dsl组成

Should-DSL将给您类似RSpec的期望。您可以使用RSpec期望API进行的所有操作,should-dsl也可以。您可以从Github获取最新版本

SpecLoud帮助您进行类似BDD的单元测试。您可以通过执行安装

pip install specloud

Ludibrio是一个用于测试双打(假人,存根和假人)的库。通过安装

pip install ludibrio

PyCukes是BDD的主要工具。它将运行场景,等等。再次,

pip install pycukes

有关更多信息,请阅读PyPi上的工具文档。

I recommend you to use a set of tools developed to help programmers in the practice of BDD and TDD. This tool set is composed by: pycukes, specloud, ludibrio and should-dsl.

Should-DSL will give you RSpec-like expectations. Everything you can do with RSpec expectation API, should-dsl does too. You can grab the latestversion from Github.

SpecLoud helps you on running BDD-like unittests. You can install it by doing

pip install specloud

Ludibrio is a library for test doubles (Mocks, Stubs and Dummies). Install it via

pip install ludibrio

And PyCukes is the main tool for BDD. It will run the Scenarios, etc. Again,

pip install pycukes

For more info please read the tools documentation at PyPi.


回答 4

很棒的帖子和答案。只是想更新包括梳洗在此列表中,因为我读pycukes被中断。有关使用BDD和Django的与梳洗好后是在这里

Great post and answers. Just wanted to update to include Freshen in this list as I read pycukes is discontinued. A good post about using BDD and Django with Freshen is here.


回答 5

您可以将“ sure”用于表达性断言(就像在RSpec中一样)

You can use “sure” for expressive assertions (just like in RSpec)


回答 6

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

与在API级别上工作的doctest不同,它对更高级别的操作进行编码,例如加载网页和提交表单。我没有使用过它,但是如果您正在寻找它,它看起来很有希望。

The Pyccuracy project is an effort to provide a domain-specific language for BDD in Python.

Unlike doctest, which works at the API level, it encodes higher-level operations such as loading a web page and submitting a form. I haven’t used it but it looks somewhat promising if that is what you’re looking for.


回答 7

我非常喜欢Pyccuracy。这些天,我正在一个中型项目中实现它。

I like Pyccuracy a lot. I’m implementing it on a mid sized project these days.


回答 8

试用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)

Try out pyspecs. Making tests easy to read and constantly running during development were two of my main goals in creating this project.

Test Code:

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)

Console Output:

# 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)

回答 9

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

如果我的解释是正确的,则只需在任何xUnit实现中重命名方法即可获得BDD框架。因此,只需继续使用标准库的unittest即可

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

I am probably completely missing the point, but what I retained of the original BDD paper was that BDD was just TDD repackaged to emphasize some best practices.

If my interpretation is correct, you can get a BDD framework just by renaming methods around in any xUnit implementation. So just go ahead and use the standard library’s unittest.

EDIT: A quick google turned up a Behaviour module in the Cheese Shop. Further searching for BDD there did not find anything else.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。