支持Python行为驱动开发的最佳工具是什么?

6 投票
3 回答
629 浏览
提问于 2025-04-16 08:15

Cucumber看起来是Ruby中进行行为驱动开发(BDD)的首选工具,通过rubypython,它也能测试Python代码,不过这个功能还在实验阶段。现在有一些Python工具,比如Pyccuracy和Freshen,但它们似乎还处于早期阶段。那么,对于Python项目来说,最好的工具是什么呢?

3 个回答

0

嗯,我可能有点偏见,但我更喜欢 pyspecs 这个东西:


from pyspecs import spec, given, when, then, the


class simple_addition(spec):
    @given
    def two_numbers(self):
        self.first = 2
        self.second = 3

    @when
    def we_add_them(self):
        self.result = add(self.first, self.second)

    @then
    def the_sum_should_equal_5(self):
        the(self.result).should.equal(5)


def add(a, b):
    return a + b

注意:作为pyspecs的作者,我非常欢迎任何反馈或合作...

1

我发现了一些有趣的Python测试库:factory_boy(https://factoryboy.readthedocs.org/en/latest/),它有点像Ruby的FactoryGirl这个工具。另外,还有一个比较新的Python测试框架叫Sure(http://falcao.it/sure/intro.html),它是基于Ruby的RSpec的。我最开始是用Python的,但现在在一家用Ruby的公司工作。我发现Ruby的测试库真的很好用,特别是RSpec。Sure看起来和RSpec很相似,值得一试。

4

看看这个lettuce吧。它想要在Python的世界里,成为类似于Cucumber的工具。不过,它现在还处于早期开发阶段。

撰写回答