Unit Testing Preset Lua Logic

I’ve stood up some basic unit testing infrastructure for the presets so that the more complicated lua methods can have automated testing:

https://app.electra.one/preset/MbCFmk0bMp3L8gxmt8Yn

This runs once after loading the preset and marks the status on the screen (as well as in the log) and then proceeds to the normal preset behaviour.

As I get more fancy with the on the fly MIDI stuff, manual regression testing with tracing is getting somewhat annoying so making this all automated is a priority for a hobby project.

I’ve also added validation for the outbound message calls to see that when the callbacks are executed they send the right MIDI messages. This could be extended to validating the methods to update the GUI objects as well. (These could actually use unit tests themselves to validate the behaviour). Also I probably should check all calls have been checked once cleanup is done.

There’s some stuff that’s still outstanding with the biggest getting full stacktraces from the unit tests as it can be a bit cryptic when it fails especially with the call history. I added a log message if the call history fails but it’s still a needle in a haystack as more tests are added.

The other one is making the overrides of the library methods like midi.sendNoteOn a bit safer and less error prone. Those ones weren’t as easily locally overriden so that ideally when the unit tests go out of scope they would be reverted to the normal behaviour. I’m pretty sure that if the unit tests fail currently they’ll bail without setting back the library functions.

Also if you get midi messages or other stuff when this is executing in unit test land, it probably wont work out well but this should usually be just as you deploy the preset while coding or on boot as it unloads the unit test infrastructure after it runs once.

2 Likes