1

I'm working on big Arduino project that involves lots proprietary libraries. Ergo, we need test scripts to ensure each library works. Is there a testing framework for Arduino similar to CPPUnit, JUnit, Cunit, etc.? It should preferable also have the ability to simulate an Arduino.

EDIT: By "Arduino Simulator" I only want something that allows observation of local variables, global variables, the different register values (at a minimum the INPUT/OUTPUT status of the pins, what is being inputted or outputted), and fake inputs into the various pins. This way, only the Arduino itself needs to be simulated, not the external hardware components like LEDs, buttons, real time clocks, motors etc.

7
  • 1
    afaik there is not such thing ... for some libraries I created my own 'stubs', with some smarter than others to test my specific application. Commented Apr 30, 2020 at 12:53
  • 1
    You could simulate an Arduino, sure, but that will be of little to no value. You need to simulate the entire system, including external stimuli. And that system is unique to you - so who would write a simulator for that...?
    – Majenko
    Commented Apr 30, 2020 at 13:18
  • Yes ... I mimiced the use of a DMX library to show all the to-be-connected lights to be shown on a PC instead as sets of pixels turning on and off ... so in your case you might have to stub it in such a way that is appropriate for you. A good start is to write all libraries NOT related directly to the Arduino or hardware and test them on a PC and when working correct, copy them to the Arduino project. Commented Apr 30, 2020 at 14:14
  • In the PlatformIO there was some --target test, but I haven't investigate how it's meant to be used or so...
    – KIIV
    Commented Apr 30, 2020 at 17:53
  • Why don't you use any common C++ unit testing framework, and provide a simulated/faked/mocked-up version of the Arduino libraries? After all, you don't have direct hardware access with them. Commented May 1, 2020 at 6:55

1 Answer 1

1

It should preferable also have the ability to simulate an Arduino.

As said in the comments, only simulating the Arduino is mostly not enough, because you would also need to simulate all the connected components. Just simulating the Arduino is a rather hard task. You can find Arduino simulators, but they always only support a rather small collection of additional hardware (mostly things like switches, LEDs, buzzers, ...). I guess the proprietary libraries, that you use, are for connecting to some extra devices (maybe are also proprietary), which will be rather complex. These devices will most likely not be supported by any of the Arduino simulators.

Also: Arduino is a beginner and fast prototyping platform. The ones, that do professional things like designing a product (which are mostly the ones, that need such test suites), will fastly move away from the Arduino platform to program an abstraction layer lower directly on the AVR platform. So why would those people need a test suite for Arduino?

Simulating electronic circuits can be really difficult, so you won't see a program, that can handle all of your circuit, including the complex parts like sensors with communication interface. That means, that you can only test your circuit and the corresponding code (which interacts with the circuit) in the real hardware. Some IDEs (like PlatformIO) might give you the possibility, to write test sketches, but you would still need to upload them to the real hardware and observe the results yourself.

Code, that is independent from the Arduino hardware, could be unit tested on the PC, but that is mostly not the case, since Arduino/microcontrollers are so hardware near. Of course, you could write mocking code for the Arduino parts, but that is often even more tedious, than just using the hardware.


As no real Arduino testing framework exists, you are down to writing own testsketches and using a good IDE (not the Arduino IDE) to organize them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.