在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