使用 python 练习 BDD

发布于 2024-07-08 08:16:40 字数 79 浏览 6 评论 0 原文

python 有哪些最先进的框架和工具可用于练习行为驱动开发? 特别是为 ruby​​ 找到类似于 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

巾帼英雄 2024-07-15 08:16:40

Lettuce 是一个类似黄瓜的 Python 工具: http://lettuce.it/

您可以在以下位置获取源代码: github.com/gabrielfalcao/生菜

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

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

不必你懂 2024-07-15 08:16:40

我真的推荐行为

在寻找 Python 的 Cucumber 克隆时,我开始使用生菜,但发现它是一个设计相当笨拙的复制品。 非常不符合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.

此生挚爱伱 2024-07-15 08:16:40

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

我个人倾向于使用 doctest archive.org/web/20110610084952/http://somethingaboutorange.com/mrl/projects/nose/1.0.0" rel="nofollow noreferrer">鼻子 和 voidspace 模拟 采用行为驱动设计风格。 具体来说,规范 nose 插件 对于 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.

双手揣兜 2024-07-15 08:16:40

我建议您使用一套开发的工具来帮助程序员实践 BDD 和 TDD。 该工具集由以下部分组成:pycukesspecloud, ludibrioshould-dsl

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

SpecLoud 帮助您运行类似 BDD 的单元测试。 您可以通过

pip install specloud

Ludibrio 来安装它。 Ludibrio 是一个测试替身库(Mocks、Stubs 和 Dummies) )。 通过安装

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.

流星番茄 2024-07-15 08:16:40

很棒的帖子和答案。 只是想更新以将 Freshen 包含在此列表中,因为我读到 pycukes 已停产。 关于使用 BDD 和 Django 与 Freshen 的好文章是 此处

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.

温柔戏命师 2024-07-15 08:16:40

您可以使用 "sure" 进行表达性断言(就像在 RSpec 中一样)

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

缪败 2024-07-15 08:16:40

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.

浅暮の光 2024-07-15 08:16:40

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

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

命比纸薄 2024-07-15 08:16:40

尝试 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)
刘备忘录 2024-07-15 08:16:40

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

如果我的解释是正确的,您只需重命名任何 xUnit实施。 因此,继续使用标准库的 unittest

编辑:快速谷歌在 Behaviour 模块中找到了 奶酪店。 进一步搜索 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文