Add unit tests to firmware

For better code quality we should gradually add unit tests for code components.
The self test cannot be run automatically in CI.

I have found this project which made some simple programs and tests for pico, it could be used as an example.

I suggest to use google test and gmock.

1 Like

This is super interesting. I do unit testing on my web stuff, but php and JS are kind of garbage languages so it’s not optional :slight_smile: (sorry for the hate, node is cool)

Unit testing on embedded C is new to me.

I had an automated firmware test rig for v3. Most of the layers are probably in china, but I have one or two here. The rig has 8 devices per layer (IO switched through 4051s). There is a script to interrogate the devices and test for the correct output. It’s a bit clunky, but was semi-useful.

I have experience with unit tests on x86 bare metal OS development. It is completely possible, not everything could be tested, but most things are.

1 Like

I don’t have any experience writing them for embedded platforms, but I’ve poked around with Marlin a bit and they have unit tests.

1 Like