Best practice to test your firmware code?

Hi Everyone,

What is the best method to test your firmware code to Electron/Photon?
Are there any good testing frameworks or code review apps that are good?

For example I have some code to control different components then the firmware for Photon is updated 1 verison. I want to be sure that everything is working fine on the new firmware. Before pushing it out to production.

Looking forward to hear your opinion and experience.

Best regards,

Writing an automatic tests module is the best solution imo.

Look in the firmware user/tests folder. Particle is using a fork of ArduinoUnit for testing.

Best practices are to use many small components that collaborate through small interfaces. For example, if you have a servo motor, write a small class to move the servo to a certain angle. Then write another class with the logic to determine the position of the servo. You can test those 2 classes in isolation.


Adding to @jvanier’s great advice, I’d suggest separating the hardware-specific parts of your code from the hardware-independent parts. The hardware-specific parts are abstracted behind interfaces so that the implementation can be mocked/stubbed during testing, which allows you to write and run tests off-device.

For on device testing, you can write sanity tests that validate the state of hardware, if the device is able to measure the state of its own hardware. When that’s not possible, you will then need an external device to monitor the hardware.

This is of course very general device - your actual approach will depend on the specifics of your situation, how much hardware dependency there is and so forth.