Isolated Unit Testing resources

I’ve found some techniques for running automated unit tests against lua code but one of the main things I can’t think of is how you unit test FiveM resources due to the natives being directly hooked into the core game. If I was writing a .NET resource I can create a “service class” with a proxy method to wrap natives and inject that in to where I woud call through to natives. Calling this proxy method from my resource code instead which would then allow mocking the service class and then providing the ability to create a full unit test suite. The biggest problem I’ve seen with FiveM frameworks is the lack of ability to run existing test suites after making changes and seeing if anything breaks without the need to spin up the server and connect. Testing is so slow and error prone and being able to use industry standard techniques to ensure code quality would be amazing.

Does anyone know of a way to achieve this in LUA?

Hey, I found this some time ago. Maybe it’ll help you a bit. I think having I’ve personally been using a JetBrains IDE with Luanalysis to develop Lua with “static” typing myself. I’ve used a self-modified version of this to generate stubs for the IDE and it has worked good for the simple stuff so far.

example of the IDE hints

1 Like