我希望能够单元测试我的Arduino代码。理想情况下,我可以运行任何测试,而无需将代码上传到Arduino。哪些工具或库可以帮助我做到这一点?

目前正在开发的Arduino模拟器可能很有用,但似乎还没有准备好使用。

Atmel的AVR Studio包含一个芯片模拟器,可能很有用,但我不知道如何将它与Arduino IDE结合使用。


当前回答

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

其他回答

试试Autodesk电路模拟器。它允许用许多其他硬件组件测试Arduino代码和电路。

如果你想在MCU之外(在桌面上)进行单元测试,请检查libcheck: https://libcheck.github.io/check/

我用它测试了几次我自己的嵌入式代码。这是一个非常健壮的框架。

我不知道有什么平台可以测试Arduino代码。

但是,有一个Fritzing平台,你可以用它来建模硬件,然后导出PCB图等。

检查的价值。

你可以在我的项目PySimAVR中使用Python进行单元测试。Arscons用于构建,simavr用于模拟。

例子:

from pysimavr.sim import ArduinoSim    
def test_atmega88():
    mcu = 'atmega88'
    snippet = 'Serial.print("hello");'

    output = ArduinoSim(snippet=snippet, mcu=mcu, timespan=0.01).get_serial()
    assert output == 'hello'

开始测试:

$ nosetests pysimavr/examples/test_example.py
pysimavr.examples.test_example.test_atmega88 ... ok

该程序允许自动运行几个Arduino单元测试。测试过程在PC上启动,但测试在实际的Arduino硬件上运行。一组单元测试通常用于测试一个Arduino库。 (这

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

GitHub项目页面:http://jeroendoggen.github.com/Arduino-TestSuite

Python包索引中的页面:http://pypi.python.org/pypi/arduino_testsuite

单元测试是用“Arduino单元测试库”编写的:http://code.google.com/p/arduinounit

对每组单元测试执行以下步骤:

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.