Page 1 of 1

Test-Driven Development (TDD)

Posted: Fri Jun 14, 2019 1:34 pm
by ToddFBass
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.

Re: Test-Driven Development (TDD)

Posted: Sun Jun 16, 2019 2:03 am
by jimmo
There's a unit testing library in micropython-lib which may be of some use to you. ... 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. ... 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". ... ster/tests

Re: Test-Driven Development (TDD)

Posted: Tue Jun 25, 2019 3:46 pm
by ToddFBass
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)

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