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

查看:452
本文介绍了我如何单元测试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天全站免登陆