3

I am building a test suite for my Lua application with Busted. I am organizing tests into different files that I would like to run in a given sequence, e.g. low-level unit tests first, up to integration tests on higher-level functions. I have way too many tests to fit in a single file.

I tried to create a "master" file that is called either via the Lua interpreter or via the Busted CLI, that calls individual test files, but I can't get it to work. E.g. I'd have run_tests.lua:

require "busted.runner"()

dofile("test1.lua")
dofile("test2.lua")
dofile("test3.lua")
-- [...]

I also want to use this file to put common scaffolding functions and switching env vars, etc. to change configurations between tests.

And then, each test[n].lua would be a regular Busted file:

describe("Module 1 test", function ()
    it("should do something sensical", function()
        -- [...]
    end)
end)

With this setup, however, the Lua interpreter cannot understand the keyword describe, even though I am requiring the Busted module in the master file.

Edit: as noted in my comment, this may be related to the busted module being local. I also tried assigning it a global variable, as in b = require "busted.runner"; b() but this still doesn't work. I am not clear on how Lua scoping should work here.

If i put the require "busted.runner"() line in the test files, only the first test runs and then exits the program (I guess that is what Busted does).

Can anyone suggest a working setup for this scenario?

1
  • OK, after reading more about load that should be related to dofile, PIL says that "it does not compile with lexical scoping". Hence describe being nil. Commented Nov 3, 2025 at 4:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.