【发布时间】:2012-09-17 21:33:58
【问题描述】:
我是 Lua 的初学者,我想在我的开发人员中使用单元测试。 我决定使用busted 一个简单易用的框架来做到这一点。
require "yaci"
require "busted"
foo = {}
foor.bar = newclass( "foo.bar" )
function foo.bar:doSomething() return "foo bar" end
describe("Unit tests for Foo.Bar", function()
it("A first test", function()
local to_test = foo.bar()
local text = to_test:doSomething()
local a = { test = say }
local b = { test = "foo bar" }
assert.same( a, b )
end)
end
但是 foo.bar 看起来无法访问...
attempt to index global 'foo' (a nil value)
describe以外的他们没问题。
有人能解释一下为什么 foo.bar 在describe 中无法访问吗?
谢谢
【问题讨论】:
-
不确定这是否是您的帖子或代码中的拼写错误,但您有
foor.bar = newclass( "foo.bar") -
指令
foo.bar:doSomething = function() return "foo bar" end也是语法错误。它可以是foo.bar.doSomething = function(self)...或function foo.bar:doSomething()...。所以请检查您的代码并更正问题。 -
我更正了我的代码并合并了两个文件。
标签: lua lua-busted