JAVA全系列 教程
3762个小节阅读:7089.3k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
单元测试(unit testing),是指对软件中的最小可测试单元进行检查和验证。
准备工作
xxxxxxxxxx
需要下载lua-resty-test-master 包
xxxxxxxxxx
#you do not need the following line if you are using
#the ngx_openresty bundle:
lua_package_path "/path/to/lua-resty-redis/lib/?.lua;;";
server {
location /test {
content_by_lua_file test_case_lua/unit/test_example.lua;
}
}
xxxxxxxxxx
service/http/test_example.lua:
local iresty_test = require "resty.iresty_test"
local tb = iresty_test.new({unit_name="example"})
function tb:init( )
self:log("init complete")
end
function tb:test_00001( )
error("invalid input")
end
function tb:atest_00002()
self:log("never be called")
end
function tb:test_00003( )
self:log("ok")
end
-- units test
tb:run()
结果:
xxxxxxxxxx
[root@localhost test]# resty -ILIB test_example.lua
0.000 [example] unit test start
0.000 [example] init complete
0.000 \_[test_0000003] ↓ok
0.000 \_[test_0000003] PASS
0.000 \_[test_000001] fail test_example.lua:11: invalid input
0.000 [example] unit test complete