How can I unit test Arduino code?

后端 未结 20 826
情深已故
情深已故 2020-12-07 06:53

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 he

20条回答
  •  没有蜡笔的小新
    2020-12-07 07:30

    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 
    
    // 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();
    }
    

提交回复
热议问题