对于“行为驱动开发”(bdd)——一种面向客户端的脚本语言,它可以压缩所有特性

Morelia的Python项目详细描述


Wheel StatusPython versionsLatest VersionLicenseBuild statusCoverageDocumentationUpdateshttps://img.shields.io/badge/code%20style-black-000000.svg

morelia是一个python行为驱动开发(bdd)库。

bdd是一个敏捷的软件开发过程,它鼓励 开发人员、qa和业务参与者之间的协作。

用自然语言编写的测试场景生成BDD基金会。 对于编写它们的非技术参与者来说,它们是可以理解的 对于开发人员和qa来说是明确的。

莫雷利亚使得开发人员很容易将BDD集成到它们现有的 单元测试框架。它很容易在鼻子下运行,pytest,tox,trial或integrate 使用django、flask或任何其他python框架,因为没有特殊的代码 必须写下来。

作为开发人员,您负责如何组织测试。不需要融入 一些其他bdd框架强制执行的严格规则。

吉祥物

http://www.naturfoto.cz/fotografie/ostatni/krajta-zelena-47784.jpg

安装

pip install morelia

快速使用指南

编写功能描述:

# calculator.featureFeature: Addition
    In order to avoid silly mistakes
    As a math idiot
    I want to be told the sum of two numbers

Scenario: Add two numbers
    Given I have powered calculator on
    When I enter "50" into the calculatorAnd I enter "70" into the calculatorAnd I press addThen the result should be "120" on the screen

创建标准python的unittest并将morelia连接到其中:

# test_acceptance.pyimportunittestfrommoreliaimportverifyclassCalculatorTestCase(unittest.TestCase):deftest_addition(self):""" Addition feature """verify('calculator.feature',self)

用你最喜欢的跑步者进行测试:unittest,nose,py.test,trial。你说出来!

$ python -m unittest -v test_acceptance  # or
$ pytest test_acceptance.py  # or
$ nosetests -v test_acceptance.py  # or
$ trial test_acceptance.py  # or
$# django/pyramid/flask/(place for your favourite test runner)

您将看到缺少哪些步骤:

F======================================================================FAIL:test_addition(test_acceptance.CalculatorTestCase)Additionfeature.----------------------------------------------------------------------Traceback(mostrecentcalllast):File"(..)test_acceptance.py",line31,intest_additionverify(filename,self)File"(..)/morelia/__init__.py",line120,inverifyexecute_script(feature,suite,scenario=scenario,config=conf)File"(..)/morelia/parser.py",line59,inexecute_scriptassertnot_found==set(),messageAssertionError:Cannotmatchsteps:defstep_I_have_powered_calculator_on(self):r'I have powered calculator on'raiseNotImplementedError('I have powered calculator on')defstep_I_enter_number_into_the_calculator(self,number):r'I enter "([^"]+)" into the calculator'raiseNotImplementedError('I enter "50" into the calculator')defstep_I_enter_number_into_the_calculator(self,number):r'I enter "([^"]+)" into the calculator'raiseNotImplementedError('I enter "70" into the calculator')defstep_I_press_add(self):r'I press add'raiseNotImplementedError('I press add')defstep_the_result_should_be_number_on_the_screen(self,number):r'the result should be "([^"]+)" on the screen'raiseNotImplementedError('the result should be "120" on the screen')----------------------------------------------------------------------Ran1testin0.013sFAILED(failures=1)

现在使用您熟悉的标准测试用例来实现步骤:

# test_acceptance.pyimportunittestfrommoreliaimportverifyclassCalculatorTestCase(unittest.TestCase):deftest_addition(self):""" Addition feature """verify('calculator.feature',self)defstep_I_have_powered_calculator_on(self):r'I have powered calculator on'self.stack=[]defstep_I_enter_a_number_into_the_calculator(self,number):r'I enter "(\d+)" into the calculator'# match by regexpself.stack.append(int(number))defstep_I_press_add(self):# matched by method nameself.result=sum(self.stack)defstep_the_result_should_be_on_the_screen(self,number):r'the result should be "{number}" on the screen'# match by format-like stringself.assertEqual(int(number),self.result)

然后再次运行:

$ python -m unittest test_acceptance

Feature: Addition
    In order to avoid silly mistakes
    As a math idiot
    I want to be told the sum of two numbers
Scenario: Add two numbers
    Given I have powered calculator on                       # pass  0.000s
    When I enter "50" into the calculator                    # pass  0.000s
    And I enter "70" into the calculator                     # pass  0.000s
    And I press add                                          # pass  0.001s
    Then the result should be "120" on the screen            # pass  0.001s
.
----------------------------------------------------------------------
Ran 1 test in 0.028s

OK

注意,morelia不会浪费任何人的时间来发明一个新的测试后端 只是为了在我们的遗嘱上增加一层读写能力。步骤是微型测试用例。 您的现场客户永远不需要知道,您的单元测试和客户测试 可以分享他们的支持方法。同一个测试按钮可以运行所有TDD和BDD测试。

查看示例目录以获取更多增强的示例,然后阅读全文 更高级主题的文档。

文档

完整文档可在http://morelia.readthedocs.org/en/latest/index.html

http://zeroplayer.com/images/stuff/sneakySnake.jpg

学分

这个包是用Cookiecutterkidosoft/cookiecutter-pypackage项目模板创建的。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
通过Java策略文件设置权限Hibernate Validator等   java@New注释不起作用   Linux下用java和C++进行socket通信   java如何正确地从数据库加载HashMap。yml文件?   在Java中创建子类的实例,是否创建其父类的实例   c#在Unity中使用Google Api Java类?   无法启动selenium。java中的WebDriver firefox在一个没有UI的盒子中   带iText 7的PDF中的java希腊字符   java中的日期格式解析异常。文本日期格式   java避免不可修改类的实例   java无法使用OpenCSV将JavaBeans写入CSV   java拥有Google PlayServices和OnConnect   java实例化发生在getInstance()之前还是getInstance()时?   java位图以错误的顺序添加到ArrayList