Lettuce:功能、场景和步骤参考

功能、场景和具有Lettuce的功能引擎的Python对象的步骤。
在这里,你会发现关于这些对象的非常“繁琐”的细节。如果你在这里找不到一个好的介绍,你可能去阅读feature的介绍比较好。
为了举例说明下面的属性和方法的使用,我们认为有一个功能文件叫做some.feature

# language: en
# just a comment

# another one
Feature: some feature
  Here comes
  The feature
  Description

  Scenario: try out something
    Given I show lettuce running
    Then I should be happy

功能

Feature.name

包含了功能名字的字符串

feature.name == 'some feature'

Feature.scenarios

场景对象列表
场景竖线可以如下使用

feature.scenarios[0].name == 'try out something'

Feature.described_at

一个功能描述对象,有对功能进行了介绍的文件和行。Lettuce使用它输出这些元数据。
属性described_at可以如下使用

# the line in which the feature started
feature.described_at.line == 5

# the filename path
'some.feature' in feature.described_at.file

# a tuple with the lines that contains the feature description
feature.described_at.description_at == (6, 7, 8)

Feature.max_length

计算组成该功能的所有行的最大长度的属性。
主要用于shell输出,查找哪里打印功能描述。
例如:

feature.max_length == 21

Feature.get_head

以当前语言中的第一个陈述来表示这个功能,后面是冒号和功能名。
例如:

feature.get_head() == 'Feature: some feature'

但是,如果用巴西葡萄牙语编写同样的功能,例如:

# language: pt-br
# apenas um comentário

# e outro
Funcionalidade: alguma funcionalidade
  Aqui vem
  a descrição
  da funcionalidade

  Cenário: ...
    ...

Feature.get_head()将会给出

feature.get_head() == 'Funcionalidade: alguma funcionalidade'

totalresult

totalresult.features_ran

整数,执行过的全部功能

totalresult.features_passed

整数,执行通过的全部功能

totalresult.scenarios_ran

整数,执行过的所有场景

totalresult.scenarios_passed

整数,执行通过的所有场景

totalresult.steps

整数,执行过的步骤数

totalresult.proposed_definitions

没有步骤定义的步骤列表

场景

scenario.steps

场景对象列表
场景属性可以如下使用

scenario.steps[0].sentence == 'try out something'

步骤

Step.sentence

展示步骤字符串

step.sentence == 'Given I show lettuce running'

Step.passed

布尔类型,如果步骤执行正确

Step.failed

布尔类型,如果步骤在执行中出错

step definition

一个可用于任何Python函数的修饰,以一个正则表达式字符串作为参数,函数参照以下步骤。

from lettuce import step

@step('I am (happy|sad)')
def show_lettuce_running_here(step, action):
    if action == 'happy':
        return # everything is fine!

    else:
        assert False, 'you should be happy, dude!'

上一篇:Lettuce: Command Line
下一篇:Lettuce: Terrian

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,079评论 25 709
  • 地形是一个Lettuce“双关语”,是它的“生活场所”,其安装和拆卸,基本上嵌入在你的Lettuce测试。 ter...
    Ailsa的简书阅读 4,057评论 0 0
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,323评论 19 139
  • 基本概念 behave要被执行,需要运行在满足下面两种情况的目录下 有feature files。这个featur...
    做测试的DanteYu阅读 16,270评论 0 7
  • 国家电网公司企业标准(Q/GDW)- 面向对象的用电信息数据交换协议 - 报批稿:20170802 前言: 排版 ...
    庭说阅读 13,850评论 6 13