类型安全,基于yaml的bdd,tdd&python的示例框架规范。
hitchstor的Python项目详细描述
Hitchstory
Hitchstory是一条Python3 testing and living documentation framework便于建造 维护示例驱动的executable specifications(有时称为 验收测试)。
它最初的设计目的是减少realistic testing的代码 一个该死的杂务,这样测试就可以被编写和运行了。
可执行规范可以编写为指定和测试 任何级别,并已成功用于替代传统 low level unit tests、integration tests和end to end tests 更容易维护测试。
规范是written using StrictYAML,而 执行它们的代码是由您用python编写的。
示例
示例.故事:
Logged in:given:website:/login# preconditionssteps:-Form filled:username:AzureDiamondpassword:hunter2-Clicked:loginEmail sent:about:|The most basic email with no subject, cc or bccset.based on:logged in# inherits from and continues from test abovesteps:-Clicked:new email-Form filled:to:Cthon98@aol.comcontents:|# long form textHey guys,I think I got hacked!-Clicked:send email-Email was sent
发动机.py:
fromhitchstoryimportBaseEngine,GivenDefinition,GivenPropertyfrommockemailcheckerimportemail_was_sentfrommockseleniumimportWebdriverfromstrictyamlimportStrclassEngine(BaseEngine):given_definition=GivenDefinition(website=GivenProperty(Str()),)defset_up(self):self.driver=Webdriver()self.driver.visit("http://localhost:5000{0}".format(self.given['website']))defform_filled(self,**textboxes):forname,contentsinsorted(textboxes.items()):self.driver.fill_form(name,contents)defclicked(self,name):self.driver.click(name)defemail_was_sent(self):email_was_sent()
fromhitchstoryimportStoryCollectionfrompathqueryimportpathqueryfromengineimportEngineStoryCollection(pathquery(".").ext("story"),Engine()).named("Email sent").play()
将输出:
RUNNING Email sent in /path/to/example.story ...
Visiting http://localhost:5000/login
Entering text hunter2 in password
Entering text AzureDiamond in username
Clicking on login
Clicking on new email
In contents entering text:
Hey guys,
I think I got hacked!
Entering text Cthon98@aol.com in to
Clicking on send email
Email was sent
SUCCESS in 0.1 seconds.
安装和设置
您可以通过pypi在任何python 3 virtualenv中安装hitchstory:
$ pip install hitchstory
但是,建议使用hitchkey安装和设置HitchStory, 它将自动设置recommended hitchstory environment。
使用pipsi:
安装挂接键pipsi install hitchkey
或者,如果您愿意,可以使用“sudo pip”安全地安装:
sudo pip install hitchkey
安装挂接钥匙后:
cd /your/project/directory
hk --tutorial hitchstory
这将创建一个名为“hitch”的目录,并在其中放置三个文件,包括一个故事,您可以通过运行以下命令来播放:
hk bdd my first
使用HitchStory
- Arguments to steps
- Story that rewrites itself
- Shortcut lookup for story names
- Handling failing tests
- Continue on failure when playing multiple stories
- Play multiple stories in sequence
- Variations
- Flaky story detection
- Generate documentation from stories
- Gradual typing of story steps
- Extra story metadata - e.g. adding JIRA ticket numbers to stories
- Given preconditions
- Hiding stacktraces for expected exceptions
- Special exception named failure
- Abort a story with ctrl-C
- Story with parameters
- Strong typing
- Running a single named story successfully
- Inherit one story from another
使用HitchStory的方法
最佳实践、工具的使用方法等。
- Recommended complementary tools
- Does hitchstory let your BA or Product Manager write stories while you just write the code?
- The importance of test realism
- Testing non-deterministic code
- What is a testing and living documentation framework?
- Screenplay Principle
- Tests are an investment
- Executable specifications
- Recommended Environment
- What is the difference betweeen a test and a story?
- How can executable specifications and living documentation be used for stakeholder collaboration?
- Triality
- Flaky Tests
设计决策和原则
有些有争议的设计决定在这里是合理的。
- Why programatically rewrite stories?
- Why does hitchstory not have a command line interface?
- Principles
- Why does hitchstory mandate the use of given but not when and then?
- Why does HitchStory use StrictYAML?
- Why does hitchstory not have an opinion on what counts as interesting to "the business"?
- Why is inheritance a feature of hitchstory stories?
- Declarative User Stories
- Two Unit Tests, Zero Integration Tests
为什么不换成X呢?
您可以使用多种工具,这就是为什么您应该使用此工具:
- Why not use Behave, Lettuce or Cucumber (Gherkin)?
- Why use hitchstory instead of a unit testing framework?
- Why not use the Robot Framework?