美文网首页
Python3 安装Cucumber (behave)

Python3 安装Cucumber (behave)

作者: 波波茶三分甜 | 来源:发表于2020-07-19 22:19 被阅读0次

    0. 序言

    Cucumber作为一个老牌的BDD框架,已经发展出各种语言的版本,Python下就有好几种,原先用的是最出名的Lettuce,但是之前Lettuce只支持Python2,不支持3。随着Python宣布2即将退役,Lettuce也宣布支持了Python3,然鹅笔者无数次安装还是无法正常运行,于是乎换了另一个Python的BDD框架behave

    1. 安装

    这里默认pip命令对应python3,然后就安装完成啦

    pip install behave

    或者

    pip install git+https://github.com/behave/behave

    我这里已经安装好了

    2. 验证安装

    在项目下创建一个feature文件夹,创建一个tutorial.feature文件,以及在feature文件夹下创建一个steps文件夹,用来存放feature对应的运行code,创建一个tutorial.py

    把demo代码放进去

    tutorial.feature

    Feature: showing off behave

      Scenario: run a simple test

        Given we have behave installed

        When we implement a test

        Then behave will test it for us!

    tutorial.py

    from behave import *

    @given('we have behave installed')

    def step_impl(context):

        pass

    @when('we implement a test')

    def step_impl(context):

        assert True is not False

    @then('behave will test it for us!')

    def step_impl(context):

        assert context.failedis False

    然后在项目目录下命令行运行behave,即可查看结果

    参考文档

    Behave Docs - Tutorial https://behave.readthedocs.io/en/latest/tutorial.html

    相关文章

      网友评论

          本文标题:Python3 安装Cucumber (behave)

          本文链接:https://www.haomeiwen.com/subject/asyffktx.html