Open davix opened 3 years ago
You are right, there is no support today for such case. I am thinking about adding it one day or the other. I call it paramterized tests.
If you feel like implementing it, please submit a PR, I'll be happy to look at it.
It seems one function can be one case, so if I create a anonymous function for each entry in the test table, will luaunit treat them separately as different cases?
Sorry, I'm a Lua newbie, can't implement the feature now.
A suggestion for @davix
local lu=require"luaunit.luaunit"
-- data for testcases
local testcases=
{
{a=1,b=1},
{a=2,b=4},
{a=3,b=9},
}
-- function to test one testcase
local function test_testcase(testcase)
local a,b=testcase.a,testcase.b
lu.assertEquals(b,a*a)
end
-- create luaunit compliant test
TestTestcases={}
for i,testcase in ipairs(testcases) do
TestTestcases["Test_"..i]=function()test_testcase(testcase)end
end
-- run test
os.exit( lu.LuaUnit.run() )
Hi, I'm using table driven tests, where all input and expected result are in a table.
However, in luaunit, it's a single case, not one case per entry in the table (like golang).
Is there a way to run the table as one case per entry?
Thanks