Hi,
I've recently starting to develop on the ESP8266 with micropython.
Since my frozen modules are getting kind off complex by now, I was wondering if there's a way of unit testing these modules.
I saw a github repo of somebody who used unit testing for his modules (https://github.com/mjkillough/feather-sonos) using ampy, but this still requires a working (and running) ESP8266.
Is there any way of performing unit tests for these modules on my linux? The biggest problem is probably units that use GPIO's, for example changing the PWM duty cycle.
Any tips are appreciated!
Frozen module unit testing
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Frozen module unit testing
I'm not sure why the fact of the module being frozen influences this.
There is a general problem of unit testing systems involving hardware interfaces: you can't easily do this on a platform lacking those interfaces. One solution is somehow to fake the interfaces but this isn't easy and can mask problems which exist only with the physical hardware. If you can it's easier and more effective to run the code on the target and script the tests. There are tools available for this notably Dave Hylands' rshell https://github.com/dhylands/rshell.git. With this you can send a script to the device, run it, and read the results back (e.g. if the script records them to a file).
This goes a long way but doesn't address all problems with hardware. Some interfaces can be tested with simple hardware add-ons such as loopbacks on UARTs. But how do you test a temperature sensor interface without doing some kind of physical temperature cycling?
Comprehensively testing systems containing hardware and firmware can be difficult.
There is a general problem of unit testing systems involving hardware interfaces: you can't easily do this on a platform lacking those interfaces. One solution is somehow to fake the interfaces but this isn't easy and can mask problems which exist only with the physical hardware. If you can it's easier and more effective to run the code on the target and script the tests. There are tools available for this notably Dave Hylands' rshell https://github.com/dhylands/rshell.git. With this you can send a script to the device, run it, and read the results back (e.g. if the script records them to a file).
This goes a long way but doesn't address all problems with hardware. Some interfaces can be tested with simple hardware add-ons such as loopbacks on UARTs. But how do you test a temperature sensor interface without doing some kind of physical temperature cycling?
Comprehensively testing systems containing hardware and firmware can be difficult.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Frozen module unit testing
For just running test scripts, you can use micropython/tools/pyboard.py
This is what the MicroPython test suite uses for the on-board tests, and rshell is built ontop of that.
This is what the MicroPython test suite uses for the on-board tests, and rshell is built ontop of that.
Re: Frozen module unit testing
You can run your tests on the linux version of MicroPython, and mock the machine module.
Re: Frozen module unit testing
[quote="deshipu"]You can run your tests on the linux version of MicroPython, and mock the machine module.[/quote]
Didn't think about mocking the whole module, thanks! Tests are running now.
Didn't think about mocking the whole module, thanks! Tests are running now.