Lua Busted 单元测试简介(Windows 环境)
简介
本文目标是在 Windows 环境下使用 Busted 进行 Lua 单元测试。
Busted 是一款 BDD 风格的 Lua 单元测试框架,支持 TAP 风格输出。
环境
- Lua 5.3.5
- LuaRocks 3.0.2
- Microsoft Windows 10 企业版 10.0.14393 版本 14393
环境配置
- 安装 LuaRocks,参照 Windows 平台 Luarocks 3.0.2 编译安装
luarocks install busted
等待安装完成即可。- 可能需要修改一下 busted.bat 文件以使 busted 可以找到测试文件同目录下的模块。参见Windows下 lua busted 找不到 module 解决办法
使用方法
busted 运行提供的 lua 脚本中的测试并给出测试结果。测试风格是 describe-it
式的,可以当做句子来读。具体语法请查看官方说明。
示例
待测试模块,保存为 sample_module.lua
:
-- sample_module.lua
local sample_module = {}
function sample_module.greet( ... )print("hello")
end
return sample_module
测试代码,保存为 busted-simple.lua
与上述代码放在同一目录:
-- busted-simple.lua
describe("Busted unit testing framework", function()describe("should be awesome", function()it("should be easy to use", function()print(package.path)assert.truthy("Yup.")end)it("should have lots of features", function()-- deep check comparisons!assert.are.same({ table = "great"}, { table = "great" })-- or check by reference!assert.are_not.equal({ table = "great"}, { table = "great"})assert.truthy("this is a string") -- truthy: not false or nilassert.True(1 == 1)assert.is_true(1 == 1)assert.falsy(nil)assert.has_error(function() error("Wat") end, "Wat")end)it("should provide some shortcuts to common functions", function()assert.are.unique({{ thing = 1 }, { thing = 2 }, { thing = 3 }})end)it("should have mocks and spies for functional tests", function()local thing = require("sample_module")spy.on(thing, "greet")thing.greet("Hi!")assert.spy(thing.greet).was.called()assert.spy(thing.greet).was.called_with("Hi!")end)end)end)
使用命令行在上述文件所在目录运行命令 busted busted-simple.lua
,得到结果:
./src/?.lua;./src/?/?.lua;./src/?/init.lua;.\?.lua;C:\local\LuaRocks-3.0.2\systree/share/lua/5.3/?.lua;C:\local\LuaRocks-3.0.2\systree/share/lua/5.3/?/init.lua;%LUA_PATH%
鈼忊棌鈼廻ello
鈼
4 successes / 0 failures / 0 errors / 0 pending : 0.016 seconds
可以看到四个测试都通过了。(乱码先忽略吧,应该是官方没有做好 utf-8 输出处理,但是核心测试功能是 ok 的)。
参考
- Busted 官网 https://olivinelabs.com/busted/
- http://lua-users.org/wiki/UnitTesting
- Error: Parse error processing dependency ‘lua_cliargs = 3.0-1’
Lua Busted 单元测试简介(Windows 环境)相关推荐
- Lua Busted 单元测试实战
目标 提供比较实用的 Lua Busted 单元测试实例. 环境 Unity 2018.2.5f1 Personal (64bit) IntelliJ IDEA 2018.2.3 (Community ...
- Windows环境搭建WeGame饥荒专用服务器(详细版)
Windows环境搭建WeGame饥荒专用服务器 前言 饥荒专用服务器 获取cluster_token令牌 注册许可证书 文件配置 路径配置 根目录 cluster.ini文件配置 地面服务器(Mas ...
- Python网络爬虫简介与环境配置
第一章 Python网络爬虫简介与环境配置 1.1 网络爬虫简介 随着互联网的快速发展越来越多的信息被发布到互联网上,这些信息被嵌入到各种各样的网页结构及样式中.虽然搜索引擎可以辅助用户搜索这些网页信 ...
- Jenkins持续集成学习-Windows环境进行.Net开发4
目录 Jenkins持续集成学习-Windows环境进行.Net开发4 目录 前言 目标 Github持续集成 提交代码到Github 从Github更新代码 git上显示构建状态 自动触发构建 Gi ...
- C++:Windows环境下基于Eclipse配置C/C++开发环境
C++:Windows环境下基于Eclipse配置C/C++开发环境 目录 Windows下的MinGW下载.安装和配置 1.MinGW下载 2.MinGW安装与配置 3.基于Eclipse配置 Wi ...
- 【DND图形库】一、简介与环境配置
一.简介与环境配置 (甲)简介 这是一个2D图形库,基于DirectX11,使用C++作为开发语言,最低支持Windows7和DirectX11显卡(如果显卡不支持,绘图效率会很低). 主要的目的是开 ...
- Python 基础入门--简介和环境配置
2019 年第 32 篇,总 56 篇文章 本文大约 1w 字,建议收藏阅读 上周结束了如何构造一个机器学习项目的系列文章,当然还有一篇简单的总结以及介绍一些入门的学习资料,不过还在整理,应该这周内会 ...
- TensorFlow2.0(一)--简介与环境搭建
简介与环境搭建 1. TensorFlow是什么 2. TensorFlow1.0与2.0架构 3. TensorFlow环境配置 1. TensorFlow是什么 TensorFlow是Google ...
- RocketMQ单机版本安装(windows环境)
本文说下windows环境中如何安装单机版的RocketMQ 文章目录 概述 资源下载 RocketMQ安装 配置环境变量 启动NAMESERVER 启动BROKER 本文小结 概述 简介 本文主要介 ...
最新文章
- VBA编程常用词汇英汉对照表
- python获取工程根目录_【Python】获取当前项目根路径/目录
- day21.模块和包
- Java—servlet简单使用
- mysql语句中怎么去重复_mysql中删除重复记录sql语句
- 非寻常实习记Ⅱ:改变中的快乐成长
- 不同路径(I和II)--动态规划
- 微服务架构 SpringCloud(一)组件和概念介绍
- ssh 根据指定端口登录远程服务器
- linux不停机释放日志,Kafka在线修改topic日志保存时长(不停机,不重启)
- 通过Adobe Acrobat DC和iText.jar完成通过pdf模板生成pdf
- 「网络安全」安全设备篇(8)——流量监控
- C++实现客户机(CLIENT)类
- 2021-07-24 centos基础设置
- C# GDAL读、写shape中文乱码
- 使用docker成功安装paddlespeech进行语音识别
- 22长安杯——个人赛
- 吊打 CLIP 平均10个点,Meta 多模态通用模型 FLAVA真香啊
- 好用并强大的图片插件:PhotoSwipe.js
- 电商ERP进销存系统V3多仓库带扫描php网页版B/S进销存系统多仓库版