Lua单元测试框架 busted

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)
	~~~
	



![执行结果:](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zaW1nLm9wZW4tb3Blbi5jb20vc2hvdy8yY2RkZmFhMWQ3NjdkZTY0OGU4ZWIyOTU1MTkyYThlMC5wbmc?x-oss-process=image/format,png)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值