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

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

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


当前回答

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

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

检查的价值。

其他回答

在没有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来调试代码或测试它。

这是在将代码安装到板上之前的最佳实践,但要确保计时,因为模拟不会在板上运行时实时运行。

保持特定于硬件的代码与其他代码分离或抽象,这样您就可以在任何拥有良好工具和最熟悉的平台上测试和调试更大的“休息”。

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?).

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

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

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