How can I unit test Arduino code?

后端 未结 20 740
情深已故
情深已故 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:38

    You can unit test in Python with my project, PySimAVR. Arscons is used for building and simavr for simulation.

    Example:

    from pysimavr.sim import ArduinoSim    
    def test_atmega88():
        mcu = 'atmega88'
        snippet = 'Serial.print("hello");'
    
        output = ArduinoSim(snippet=snippet, mcu=mcu, timespan=0.01).get_serial()
        assert output == 'hello'
    

    Start test:

    $ nosetests pysimavr/examples/test_example.py
    pysimavr.examples.test_example.test_atmega88 ... ok
    

提交回复
热议问题