类型安全,基于yaml的bdd,tdd&python的示例框架规范。

hitchstor的Python项目详细描述


Hitchstory

Hitchstory是一条Python3 testing and living documentation framework便于建造 维护示例驱动的executable specifications(有时称为 验收测试)。

它最初的设计目的是减少realistic testing的代码 一个该死的杂务,这样测试就可以被编写和运行了。

可执行规范可以编写为指定和测试 任何级别,并已成功用于替代传统 low level unit testsintegration testsend 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

使用HitchStory的方法

最佳实践、工具的使用方法等。

设计决策和原则

有些有争议的设计决定在这里是合理的。

为什么不换成X呢?

您可以使用多种工具,这就是为什么您应该使用此工具:

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

推荐PyPI第三方库


热门话题
java Jetty是否有请求缓存?   数组中的java 2值与我的数据帧中的2列对应   对象序列化期间的java DbUtils类型转换问题   java根面板中不显示所有单独的面板   java通过代理或SSH隧道连接Hbase API   java困惑:与经典MVC控制器相比,JSF2中bean的角色   java在我的Triangle类中“找不到符号错误”   java在Android中设置从路径到自定义按钮的图像   java不绕轨道旋转椭圆   AES在socket上搞砸了序列化/反序列化。无效的流标头。JAVA   java在数组中搜索term和if语句   线程“main”java中出现异常。util。正则表达式。PatternSyntaxException:在索引0附近悬挂元字符“*”*   Websphere上的java Google反射无法打开url连接   java为什么inc/dec频道什么都不做?   java KeyListener无法访问keyPressed方法