Skip to content

一个使用起来超方便的LUA 单元测试(UT)框架(A very simple and Easy use LUA UT test framwork)。欢迎大家到 http://www.ostack.cn 交流编程经验

Notifications You must be signed in to change notification settings

ZhaoGuangYue1986/LuaUnit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

LuaUnit

一个使用起来超方便的LUA 单元测试(UT)框架

A very simple and Easy use LUA UT test framwork

欢迎大家到 http://www.ostack.cn 交流编程经验

支持特性

1.支持setUp/tearDown特性,用户可以自己定义setUp和tearDown函数,框架将在所有用例运行前可以加载调用此函数

1.Support setUp/tearDown features, users can define setUp and tearDown functions themselves, the framework will load and call this function before all use cases are run。

2.支持caseSetUp/caseTearDown特性,用户可以自己定义caseSetUp和caseTearDown函数,框架将在每个用例运行前可以加载调用此函数

2.Support caseSetUp/caseTearDown features, users can define caseSetUp and caseTearDown functions by themselves, the framework will load and call this function before each use case runs

使用方法(How to use)

使用前需要require 本模块,通过返回的变量来调用提供的方法。同时,我们提供了Assert类,用于参数的判断

Should require Log first, then use the return val's function, same time we provide Assert class for judge the result

使用示例

请参考Sample.lua

please see Sample.lua

----------------use sample----------------

-----1.引入luaUnit模块

-----1.Require LuaUnit Model

local LuaUnit = require("LuaUnit")

-----2.从luaUnit派生出我们自己的测试类

-----2.Derive an instance of ourselves from luaUnit)

local TestUnit = LuaUnit:derive("TestUnit")

-----3.如果需要测试前准备的话,可以重写setUp方法,此方法将在所有用例前调用

-----3.override setUp function if needed, this function will be called before test case run

function TestUnit:setUp()

----You can use needTrace function to open lua debug trace

Assert:needTrace(false)

print("This function will be called BEFORE ALL test run,you can define you own setUp funtion")

end

-----4.如果需要测试前准备的话,可以重写tearDown方法,此方法将在所有用例运行完以后调用

-----4. override tearDown function if needed, this function will called after all test case run

function TestUnit:tearDown()

----You can use needTrace function to open lua debug trace

Assert:needTrace(false)

print("This function will be called AFTER ALL test run,you can define you own tearDown funtion")

end

-----5.如果需要测试前准备的话,可以重写caseSetUp方法,此方法将每个用例运行前调用

-----5.Third override tearDown function if needed, this function will called before each test case run

function TestUnit:caseSetUp()

print("This function will be called BEFORE EACH test run,you can define you own setUp funtion")

end

-----6.如果需要测试前准备的话,可以重写caseSetUp方法,此方法将每个用例运行前调用

-----6.Third override tearDown function if needed, this function will called before each test case run

function TestUnit:caseTearDown()

print("This function will be called AFTER EACH test run,you can define you own caseTearDown funtion")

end

-----7.设计我们的用例,要求:所有用例必须以test开头

-----7.design our test cases,notes:all test case should start with "test"

-- Need Test function

local function foo()

return 2

end

function TestUnit:testNotEqual()

Assert:equal(1, 2)

end

function TestUnit:testEqual2()

Assert:equal(1, 1)

end

function TestUnit:testFo()

Assert:equal(1, foo())

end

function TestUnit:testAssertIsTrue()

Assert:isTrue(true)

-- Assert:isTrue(false)

end

function TestUnit:testAssertIsFalse()

Assert:isFalse(false)

--Assert:isFalse(true)

end

-----8.执行所有用例

-----8.run this test class

TestUnit:run()

相關倉庫

https://github.com/ostack/LuaUnit

https://github.com/ostack/LuaLogger

https://github.com/ostack/LuaMock

About

一个使用起来超方便的LUA 单元测试(UT)框架(A very simple and Easy use LUA UT test framwork)。欢迎大家到 http://www.ostack.cn 交流编程经验

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages