如何对 Arduino 代码进行单元测试? [英] How can I unit test Arduino code?

查看:41
本文介绍了如何对 Arduino 代码进行单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够对我的 Arduino 代码进行单元测试.理想情况下,我无需将代码上传到 Arduino 即可运行任何测试.哪些工具或库可以帮助我解决这个问题?

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 help me with this?

有一个 正在开发中的 Arduino 模拟器 可能很有用,但它没有似乎还没有准备好使用.

There is an Arduino emulator in development which could be useful, but it doesn't yet seem to be ready for use.

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

AVR Studio from Atmel contains a chip simulator which could be useful, but I can't see how I would use it in conjunction with the Arduino IDE.

推荐答案

在没有任何预先存在的 Arduino 单元测试框架的情况下,我创建了 ArduinoUnit.这是一个简单的 Arduino 草图,演示了它的用法:

In the absence of any pre-existing unit test frameworks for Arduino, I have created ArduinoUnit. Here's a simple Arduino sketch demonstrating its use:

#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 代码进行单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆