自动化测试之行为驱动

行为驱动

行为驱动开发,英文全称是Behavior Driven Development,英文缩写为BDD。lettuce是实现BDD开发模式的一种测试框架,实现了使用自然语言来执行相关联测试的代码的需求。lettuce是基于Cucumber的一款非常易于使用的BDD工具,可以执行纯文本的功能描述。
环境准备:
在py -2交互环境下安装lettuce模块。pip install lettuce。
第一个英文语言行为驱动测试的例子:
测试逻辑:
(1)从lettuce全局变量命名空间world中取得一个整数。
(2)计算该整数的阶乘。
(3)断言计算结果的正确性。
features
-steps.py(写测试脚本和自然语言的测试步骤进行对应)
-xxxx.feature(写自然语言的测试步骤的)
在cmd中,cd进入features的父目录,执行lettuce
在这里插入图片描述

Feature: Compute factorial
  In order to play with Lettuce
  As beginners
  We'll implement factorial

  Scenario: Factorial of 0
    Given I have the number 0
    When I compute its factorial
    Then I see the number 1

  Scenario: Factorial of 1
    Given I have the number 1
    When I compute its factorial
    Then I see the number 1

  Scenario: Factorial of 2
    Given I have the number 2
    When I compute its factorial
    Then I see the number 2

  Scenario: Factorial of 3
    Given I have the number 3
    When I compute its factorial
    Then I see the number 6

steps.py

#encoding=utf-8
from lettuce import *

# 用于计算整数的阶乘函数
def factorial(number):
    number = int(number)
    if (number &
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值