在pyhistorian之上构建的黄瓜状bdd框架

pycukes的Python项目详细描述


比库克斯

pycukes是一个类似黄瓜的bdd工具,建立在pyhistorian之上。 PyCukes的创建是为了填补PyHistorian留下的空白,因此可以首先使用文本文件与您的涉众交谈,而不是像PyHistorian这样简单的不可处理的Python文件。

用法

首先,确保您已经安装了Story嫒runner、PyHistorian和PyCukes。 默认情况下,如果您只是从命令行调用pycukes到某个目录中,它将查找stories目录(期望您的故事文件在那里),然后查找step_definitions目录(期望您的步骤定义在那里)。 按照约定,每个故事文件都以.story结尾,比如calculator.story,每个步骤定义都应该以steps.py结尾,比如calculator_steps.py

所以,假设您有目录树:

|-- calculator
   `-- stories
       |-- calculator.story
       `-- step_definitions
           `-- calculator_steps.py

要运行您的故事,您可以简单地调用:

$ pycukes

或者,如果您可以确切地指定运行的报道:

$ pycukes stories/calculator.story

参数

-s or --stories-dir  --  specify your stories directory
-t or --steps-dir  --  specify your step definitions directory
-n or --no-colors  --  tells pycukes not to show colored output
-c or --colored (default) -- tells pycukes to show colored output
-l or --language (en-us by default) -- specify your story language [en-us and pt-br are supported]

实际示例

目录树:

hugo@hugo-laptop:~/app$ tree
.
`-- stories
    |-- bowling_game.story
    `-- step_definitions
        `-- bowling_game_steps.py

保龄球游戏的内容。故事文件:

hugo@hugo-laptop:~/app$ cat stories/bowling_game.story
Story: Bowling Game
  As a bowling player
  I want to play bowling online
  So that I can play with everyone in the world

    Scenario 1: Gutter Game
      Given I am playing a bowling game
      When I hit no balls
      Then I have 0 points

保龄球比赛步骤.py的内容:

hugo@hugo-laptop:~/app$ cat stories/step_definitions/bowling_game_steps.py
from pycukes import *

class BowlingGame(object):
    score = 1
    def hit(self, balls):
        pass


@Given('I am playing a bowling game')
def start_game(context):
    context._bowling_game = BowlingGame()

@When('I hit no balls')
def hit_no_balls(context):
    context._bowling_game.hit(0)

@Then('I have 0 points')
def i_have_zero_points(context):
    assert context._bowling_game.score == 0

跑步:

hugo@hugo-laptop:~/app$ pycukes stories/bowling_game.story
Story: Bowling Game
  As a bowling player
  I want to play bowling online
  So that I can play with everyone in the world

  Scenario 1: Gutter Game
    Given I am playing a bowling game   ... OK
    When I hit no balls   ... OK
    Then I have 0 points   ... FAIL

  Failures:
    File "stories/step_definitions/bowling_game_steps.py", line 19, in i_have_zero_points
      assert context._bowling_game.score == 0
    AssertionError


  Ran 1 scenario with 1 failure, 0 errors and 0 pending steps

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

推荐PyPI第三方库


热门话题
JavaMaven没有识别junit测试   正则表达式替换Java中字符串中的所有“(“and”)”   文件移动到另一台计算机时出现java错误“实例化servlet类”   服务器上的java服务   Spring数据JPA上的java嵌套@Transactional注释行为   eclipse中的Java Tomcat项目   java在Tomcat上部署web应用程序   如何解决“java.lang.IllegalStateException:ArrayAdapter要求资源ID为TextView”错误?   java在条形码上方添加文本,并使用烧烤更改字体大小   java与php基准测试   java使用正则表达式提取特定模式   java扫描器。findInLine()大量泄漏内存   java HTTP:差异请求属性和POST参数   返回空指针的Java方法?   java验证密码不包含名称中的3个以上连续字符   Java中带泛型的静态多态性   java在Android中获得最后一个已知位置   java为什么Groovy的Map比Array更具可伸缩性?   编码如何在Java中生成八进制字符串?   java Hibernate:使用单例会话写入日志(无刷新)