bluebird75 / luaunit

LuaUnit is a popular unit-testing framework for Lua, with an interface typical of xUnit libraries (Python unittest, Junit, NUnit, ...). It supports several output formats (Text, TAP, JUnit, ...) to be used directly or work with Continuous Integration platforms (Jenkins, Maven, ...).
Other
572 stars 137 forks source link

Mock globals, other function and tables #142

Closed Ismoh closed 2 years ago

Ismoh commented 2 years ago

I am using LuaUnit since some months, but now I got to a point where I need to mock a global function provided by a API I do not have access to on github workflow. I already tried to mock those and it's working, but I am not sure, if there is a better way to do so.

I had several looks on the documentation, but it looks like I am blind!

Can someone give me an example, how to mock things?

Thanks in advantage!

Edit: This is, how I try to mock stuff, but feels hacky, somehow? It's working..

https://github.com/Ismoh/NoitaMP/blob/809312fc591a1145d702e050f40372b4cfcd6fcb/.testing/tests/files/scripts/util/file_util_test.lua#L13

https://github.com/Ismoh/NoitaMP/blob/809312fc591a1145d702e050f40372b4cfcd6fcb/.testing/tests/files/scripts/util/file_util_test.lua#L35-L37

bluebird75 commented 2 years ago

You are not blind / ! LuaUnit only covers unit-testing, not mocking.

There are plenty of library who provide mock capabilities in Lua, I am sure that you will find one which you may want to combine with LuaUnit.

Ismoh commented 2 years ago

Thanks for your time and reply! I appreciate this a lot.

Okay, so my 'mocking' is working for now. Going to have a look, when it's urgent!