Lua单元测试框架 busted
busted 是 Lua 的单元测试框架,示例代码:
require("busted") describe("Busted unit testing framework", function() describe("should be awesome", function() it("should be easy to use", function() 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.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("thing_module") spy.spy_on(thing, "greet") thing.greet("Hi!") assert.spy(thing.greet).was.called() assert.spy(thing.greet).was.called_with("Hi!") end) end) end)
执行结果:
本文由用户 openkk 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!