Test-Driven Development (TDD)

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Posts: 1
Joined: Fri Jun 14, 2019 1:29 pm

Test-Driven Development (TDD)

Post by ToddFBass » Fri Jun 14, 2019 1:34 pm

Hello smart people. I'm trying to develop an approach to test-driving MicroPython. I'm using the Expressif ESP32. I'm finding lots of information on developing MicroPython, and lots of information on test-driving Python, but nothing on test-driving MicroPython.

I'm assuming I want tests maintained and executed off-chip, with the hardware mocked to characterize software behavior. I can see some advantages to running tests on-chip.

At this point any input or suggestions would be helpful.

User avatar
Posts: 240
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: Test-Driven Development (TDD)

Post by jimmo » Sun Jun 16, 2019 2:03 am

There's a unit testing library in micropython-lib which may be of some use to you. https://github.com/micropython/micropyt ... r/unittest (You should be able to install it with upip on your ESP32)

Code: Select all

>>> import upip
>>> upip.install('unittest')
Have a look at e.g. https://github.com/micropython/micropyt ... st_glob.py for a more comprehensive example of using the library.

For testing off-chip, you might find the Unix or Windows ports of MicroPython useful (where you can also use this same library).

Mocking is a bit more of a challenge. At least it's Python so creating stub/mock/fake implementations of various APIs isn't too hard to do, but if you're used to one of the more full-featured mocking libraries from regular Python you might find that a bit frustrating!

You might also find it interesting to look at the MicroPython tests themselves, many of which compare the stdout of code running under MicroPython to output runnning under CPython. But you can also specify the expected output manually, so that might be useful if you can make your mocks do stuff like output "Pin 7 changed to 1". https://github.com/micropython/micropyt ... ster/tests

Post Reply