busted is a unit testing framework supporting Lua >= 5.1, luajit >= 2.0.0, and moonscript.
Questions tagged [lua-busted]
24 questions
8
votes
1 answer
Mocking local imports when unit-testing Lua code with Busted
I'm very new to Lua and I'm trying to test a script I have running with an Nginx server. I've been recommended Busted but I can't seem to figure out how to mock some of the local imports.
The Lua code imports the following:
local http = require…

wonderv
- 143
- 1
- 7
5
votes
1 answer
How do I write busted unit tests for functions that return ok,err?
I have a Lua function that returns false followed by error message and want to test its behavior using the busted testing framework. Right now I am doing it a bit like this:
function safe_divide(a, b)
if b > 0 then -- buggy! should be b ~= 0
…

hugomg
- 68,213
- 24
- 160
- 246
4
votes
1 answer
Unit Testing local function in Lua
So I'm using Busted to create unit tests for an existing Lua file, without changing the code in the file if possible. The file imports another file, and then stores various methods from that file in local functions, like so.
[examplefile.lua]
local…

Ryan
- 115
- 1
- 8
4
votes
1 answer
Mocking methods in an existing lua file during Busted tests
I'm wanting to write unit tests for an existing lua file using Busted. I want to swap out some of the methods during the test, so that the file runs with the mocked/stubbed methods rather than the real ones (otherwise it will fail). Some of the…

Ryan
- 115
- 1
- 8
4
votes
1 answer
Busted has_error causes tests to error
I am attempting to use busted for unit tests on a lua project. I have a module that looks something like this:
-- src/rom/apis/display.lua
local _displayModes = {
single = 1,
mirrored = 2,
extended = 3,
immersive = 4
}
local _validMode =…

aaronmallen
- 1,418
- 1
- 12
- 29
3
votes
2 answers
Is there a way to run a Busted test suite in parallel?
The test suite for my Lua project is split up into multiple files inside the spec/ directory.
Is there a way to ask busted to run those tests in parallel? If I call busted without any arguments it runs all the tests sequentially.

hugomg
- 68,213
- 24
- 160
- 246
2
votes
1 answer
Symbol not found: OpenSSL_version_num
I am trying to create a kong plugin. It works great when running as part of kong server but when I am trying to write some unit tests with busted, resty.openssl.digest func load fails. More specifically while loading the version.lua
I am not sure…

ImGroot
- 796
- 1
- 6
- 17
2
votes
2 answers
busted No test files found matching Lua pattern: spec
my directory
the contents of the file 'hhh.lua' is the same as file 'btest_spec.lua' (see my directory)
when I run 'busted' (just use commond 'busted') ,it return an error:
0 successes / 0 failures / 1 error / 0 pending : 0.00003 seconds
Error → No…

kylehz
- 39
- 4
2
votes
1 answer
Issue with creating JSON output for Busted lua unit testing
So I have some simple unit tests setup in busted. I am a little new to LUA, so I may be missing something obvious.
When I run:
lua test.lua
I get expected results (7 succeed, 1 failed on purpose to try out busted) in the nice terminal output.
My…

Brandon
- 261
- 1
- 8
- 17
1
vote
0 answers
Unit and Integration testing of custom Kong plugin using busted
I have been trying to explore unit and integration testing frameworks for custom kong plugins. I'm very new to Lua and I started exploring busted and I was not able to successfully run tests on the plugin.
Here are the steps I followed -
I ran a…

Ashay Fernandes
- 353
- 4
- 14
1
vote
1 answer
How to obtain a full stack trace when test fails with an error?
Especially when developing sort-of test driven, it would be really useful if busted output a full stack trace for tests failing with an error. I can't seem to find a busted option that would allow this.
Is there any way I can get a full stack trace…

Thomas W
- 14,757
- 6
- 48
- 67
1
vote
2 answers
Do the assertions in the luassert library have a `level` parameter similar to the builtin `error` function?
I am currently writing a test suite using busted/luassert and since I have put some assertions in a separate function I am getting inaccurate stack traces. For example, consider the following test suite (a_spec.lua):
local function…

hugomg
- 68,213
- 24
- 160
- 246
1
vote
0 answers
Busted won't recognize certain functions
I'm using the Busted framework to test my lua programs. I have newest busted version
user ~ $ busted --version
2.0.rc12-0
I ran this program (its called etl)
goto statement
::statement::
error loading module 'etl' from file './etl.lua':
…

Sam
- 108
- 2
- 9
1
vote
2 answers
How to do unit testing with busted in openresty?
I have a bunch of lua files which I use to handle different urls in nginx, like this:
location /tag {
set $env 'prod';
set $redis_ttl 7776000;
content_by_lua_file 'conf/match.lua';
log_by_lua_file 'conf/log.lua';
}
Each…

Vladimir Lebedev
- 1,207
- 1
- 11
- 25
1
vote
3 answers
Testing lua script with busted
I'm attempting to test our Freeswitch lua scripts with busted and am running into a snag. The gist of it is that I need to be able to spy on code like the following
local req_host =…

user3587406
- 51
- 1
- 6