我希望能够单元测试我的Arduino代码。理想情况下,我可以运行任何测试,而无需将代码上传到Arduino。哪些工具或库可以帮助我做到这一点?
目前正在开发的Arduino模拟器可能很有用,但似乎还没有准备好使用。
Atmel的AVR Studio包含一个芯片模拟器,可能很有用,但我不知道如何将它与Arduino IDE结合使用。
我希望能够单元测试我的Arduino代码。理想情况下,我可以运行任何测试,而无需将代码上传到Arduino。哪些工具或库可以帮助我做到这一点?
目前正在开发的Arduino模拟器可能很有用,但似乎还没有准备好使用。
Atmel的AVR Studio包含一个芯片模拟器,可能很有用,但我不知道如何将它与Arduino IDE结合使用。
当前回答
试试Autodesk电路模拟器。它允许用许多其他硬件组件测试Arduino代码和电路。
其他回答
看起来乳香就能完美地完成这项工作。
Emulino是Greg Hewgill为Arduino平台开发的模拟器。(源)
GitHub库
该程序允许自动运行几个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.
保持特定于硬件的代码与其他代码分离或抽象,这样您就可以在任何拥有良好工具和最熟悉的平台上测试和调试更大的“休息”。
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?).
有一个叫ncore的项目,它为Arduino提供了原生内核。并允许您为Arduino代码编写测试。
来自项目描述
本机核心允许您编译和运行Arduino草图 PC,一般无需修改。的原生版本 标准的Arduino功能,以及一个命令行解释器 草图的输入通常来自硬件 本身。
同样在“我需要使用它什么”部分
如果要构建测试,则需要从 http://cxxtest.tigris.org。NCORE已经用cxxtest 3.10.1进行了测试。
基本Arduino是用C和c++编写的,甚至Arduino的库也是用C和c++编写的。因此,简单地说,只需将代码处理为C和c++,并尝试进行单元测试。这里,通过“句柄”这个词,我的意思是你改变所有的基本语法,如串行。Println到sysout, pinmode到变量,void循环到while()循环,该循环在keystock或某些迭代后中断。
我知道这是一个漫长的过程,不那么直接。根据我个人的经验,一旦你开始使用它,它就会变得更可靠。
-Nandha_Frost