我希望能够单元测试我的Arduino代码。理想情况下,我可以运行任何测试,而无需将代码上传到Arduino。哪些工具或库可以帮助我做到这一点?
目前正在开发的Arduino模拟器可能很有用,但似乎还没有准备好使用。
Atmel的AVR Studio包含一个芯片模拟器,可能很有用,但我不知道如何将它与Arduino IDE结合使用。
我希望能够单元测试我的Arduino代码。理想情况下,我可以运行任何测试,而无需将代码上传到Arduino。哪些工具或库可以帮助我做到这一点?
目前正在开发的Arduino模拟器可能很有用,但似乎还没有准备好使用。
Atmel的AVR Studio包含一个芯片模拟器,可能很有用,但我不知道如何将它与Arduino IDE结合使用。
当前回答
simavr是一个使用AVR -gcc的AVR模拟器。
它已经支持一些ATTiny和ATMega微控制器,而且根据作者的说法,很容易添加更多的微控制器。
示例中包含simduino,这是一个Arduino模拟器。它支持运行Arduino引导加载程序,并可以通过Socat(修改后的Netcat)使用avrdude进行编程。
其他回答
我在编写Arduino代码时使用Searduino。Searduino是Arduino模拟器和开发环境(Makefiles, C代码…),可以使用您最喜欢的编辑器在C/ c++中轻松破解。您可以导入Arduino草图并在模拟器中运行它们。
Searduino 0.8截图:http://searduino.files.wordpress.com/2014/01/jearduino-0-8.png
Searduino 0.9将发布,并在最后的测试完成后立即录制视频....一两天后。
在模拟器上测试并不是真正的测试,但它确实帮助我找到了许多愚蠢的/逻辑错误(忘记执行pinMode(xx, OUTPUT)等)。
顺便说一句:我是Searduino开发人员之一。
在没有Arduino单元测试框架的情况下,我创建了ArduinoUnit。下面是一个简单的Arduino草图,展示了它的使用:
#include <ArduinoUnit.h>
// Create test suite
TestSuite suite;
void setup() {
Serial.begin(9600);
}
// Create a test called 'addition' in the test suite
test(addition) {
assertEquals(3, 1 + 2);
}
void loop() {
// Run test suite, printing results to the serial port
suite.run();
}
使用带有Arduino库的Proteus VSM来调试代码或测试它。
这是在将代码安装到板上之前的最佳实践,但要确保计时,因为模拟不会在板上运行时实时运行。
该程序允许自动运行几个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.
有一个叫ncore的项目,它为Arduino提供了原生内核。并允许您为Arduino代码编写测试。
来自项目描述
本机核心允许您编译和运行Arduino草图 PC,一般无需修改。的原生版本 标准的Arduino功能,以及一个命令行解释器 草图的输入通常来自硬件 本身。
同样在“我需要使用它什么”部分
如果要构建测试,则需要从 http://cxxtest.tigris.org。NCORE已经用cxxtest 3.10.1进行了测试。