Frozen module unit testing

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
thijsdv
Posts: 5
Joined: Mon Jan 30, 2017 8:35 am

Frozen module unit testing

Post by thijsdv » Fri Feb 03, 2017 1:41 pm

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!

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Frozen module unit testing

Post by pythoncoder » Sat Feb 04, 2017 8:05 am

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.
Peter Hinch
Index to my micropython libraries.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Frozen module unit testing

Post by dhylands » Sat Feb 04, 2017 6:49 pm

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.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Frozen module unit testing

Post by deshipu » Sat Feb 04, 2017 8:57 pm

You can run your tests on the linux version of MicroPython, and mock the machine module.

thijsdv
Posts: 5
Joined: Mon Jan 30, 2017 8:35 am

Re: Frozen module unit testing

Post by thijsdv » Wed Feb 08, 2017 7:22 am

[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.

Post Reply