How can I unit test Arduino code?

后端 未结 20 733
情深已故
情深已故 2020-12-07 06:53

I\'d like to be able to unit test my Arduino code. Ideally, I would be able to run any tests without having to upload the code to the Arduino. What tools or libraries can he

相关标签:
20条回答
  • 2020-12-07 07:24

    I am not aware of any platform which can test Arduino code.

    However, there is the Fritzing platform, which you can use to model the hardware and later on export PCB diagrams and stuff.

    Worth checking.

    0 讨论(0)
  • 2020-12-07 07:24

    Keep hardware-specific code separate or abstracted away from the rest so you can test and debug that bigger "rest" on any platform for which you have good tools and with which you're familiar most.

    Basically, try to build as much of the final code from as many known-to-work building blocks as possible. The remaining hardware-specific work will then be much easier and faster. You may finish it by using existing emulators and/or emulating devices on your own. And then, of course, you'll need to test the real thing somehow. Depending on circumstances, that may or may not be very well automatable (i.e. who or what will press buttons and provide other inputs? who or what will observe and interpret various indicators and outputs?).

    0 讨论(0)
  • 2020-12-07 07:24

    In basic Arduino is written with C and C++, even libraries of arduino are written in C and C++. So,in simple terms just handle the code as C and C++ and try doing the unit testing. Here, by the word "handle" I mean you to change all the basic syntax like serial.println to sysout, pinmode to varaibles, void loop to while() loop which breaks either in keystock or after some iteration.

    I know this is little a long process and not so straight forward.On my personal experience, once you get to do with it, this turns to be more reliable.

    -Nandha_Frost

    0 讨论(0)
  • 2020-12-07 07:26

    It seems that emulino would do the job perfectly.

    Emulino is an emulator for the Arduino platform by Greg Hewgill. (Source)

    GitHub repository

    0 讨论(0)
  • 2020-12-07 07:26

    We are using Arduino boards for data acquisition in a large scientific experiment. Subsequently, we have to support several Arduino boards with different implementations. I wrote Python utilities to dynamically load Arduino hex images during unit testing. The code found on the link below supports Windows and Mac OS X via a configuration file. To find out where your hex images are placed by the Arduino IDE, hit the shift key before you hit the build (play) button. Hit the shift key while hitting upload to find out where your avrdude (command line upload utility) is located on your system / version of Arduino. Alternatively, you can look at the included configuration files and use your install location (currently on Arduino 0020).

    http://github.com/toddstavish/Python-Arduino-Unit-Testing

    0 讨论(0)
  • 2020-12-07 07:26

    This program allows automated running of several Arduino unit tests. The testing process is started on the PC but the tests run on the actual Arduino hardware. One set of unit tests is typically used to test one Arduino library. (this

    Arduino Forum: http://arduino.cc/forum/index.php?topic=140027.0

    GitHub project page: http://jeroendoggen.github.com/Arduino-TestSuite

    Page in the Python Package Index: http://pypi.python.org/pypi/arduino_testsuite

    The unit tests are written with the "Arduino Unit Testing Library": http://code.google.com/p/arduinounit

    The following steps are performed for each set of unit tests:

    • Read the config file to find out which tests to run
    • The script compiles and uploads an Arduino sketch that contains the unit testing code.
    • The unit tests are run on the Arduino board.
    • The results of the test are printed over the serial port and analyzed by the Python script.
    • The script starts the next test, repeating the above steps for all test that are requested in the configuration file.
    • The script prints a summary showing an overview of all the failed/passed tests in the complete testsuite.
    0 讨论(0)
提交回复
热议问题