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
ToddFBass
Posts: 2
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
jimmo
Posts: 648
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

Hi,
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

ToddFBass
Posts: 2
Joined: Fri Jun 14, 2019 1:29 pm

Re: Test-Driven Development (TDD)

Post by ToddFBass » Tue Jun 25, 2019 3:46 pm

Thank you, jimmo. I've started going the route of creating a emulation library for testing off-chip. Rather than testing stdout, I'm adding methods, functions, variables, and attributes with names ending in "ForTesting". It's very sparse, and I don't know how much I'm going to extend it. It's pretty much an experiment at this point. I've committed it to PyPi with "planning" status (not ready for alpha) https://pypi.org/project/esp32-machine-emulator/

I agree with you that on-chip testing is also useful, but for TDD I need to do off-chip test-driving.

Post Reply