Python2 Module 之 Lettuce
程序员文章站
2022-05-10 19:32:23
...
安装
pip install lettuce
测试用例
01 测试用例有两个部分组成: 01 测试方法(测试时执行的函数) 02 行为文件(测试步骤描述文件)
02 执行测试用例的过程: 测试方法 - > 读取 - > 行为文件 - > 获取参数 - > 执行测试方法 - > 断言
03 行为文件中的描述 与 测试方法的装饰器中的描述 必须一一对应(可以使用正则表达式进行匹配, 这样就可以在行为文件中修改参数了)
测试文件
测试方法文件
from lettuce import *
'''
概述: 这里写三个方法:
01 使用装饰器匹配行为文件, 读取一个数字
02 计算阶乘
03 比较结果
'''
from lettuce import *
'''
FileName: steps.py
概述: 这里写三个方法:
01 使用装饰器匹配行为文件, 读取一个数字
02 计算阶乘
03 比较结果
'''
# 匹配行为文件中的: Given I have the number 0
@step('I have the number (\+d)') # (+\d) 正则匹配
def have_the_number(step, number):
world.number = int(number)
# 匹配行为文件中的: I compute its factorial
@step('I compute its factorial')
def compute_its_factorial(step):
world.number = factorial(world.number)
# 匹配行为文件中的: I see the number
@step('I see the number (\+d)')
def compute_its_factorial(step,expected):
expected = int(expected)
assert world.number == ecpected,"got %d" % world.number
def factorial(number):
number = int(number)
if(number == 0) or (number == 1):
return 1
else:
return number*factorial(number-1)
测试行为文件
场景:
我有一个数字0
我去计算它的阶乘
我看到了结果1
场景…
转为代码如下:
Feature: Compute factorial
FileName: zero.feature
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 3
Given I have the number 3
When I compute its factorial
Then I see the number 6
Scenario: Factorial of 6
Given I have the number 6
When I compute its factorial
Then I see the number 6
执行测试用例
运行lettuce自动测试
注: lettuce 不兼容 python3
01 打开 cmd
02 cd 行为文件的目录
03 输入 lettuce 请勿输入其他, 这里会自动向下级目录查找行为文件, 并完成行为文件 和 测试方法文件的关联, 继而完成测试用例
推荐阅读
-
ES6新特性之模块Module用法详解
-
vue 之 css module的使用方法
-
python3.6之filter()函数与python2的区别讲解
-
Android之把app作为独立的module导入其他项目遇到的坑
-
python自动化测试之web运行代码报错:importError:no module named selenium
-
NodeJS学习笔记之Module的简介
-
Nginx之——nginx-rtmp-module搭建流媒体服务器实现直播
-
PowerShell小技巧之使用New-Module命令动态创建对象
-
Nginx会话保持之nginx-sticky-module模块
-
Nginx会话保持之nginx-sticky-module模块