DEV Community

Wilberto Morales
Wilberto Morales

Posted on • Originally published at wilbertom.com

Library Testing Functionality

We would save a lot of developer time if libraries included testing functionality. One example of this is the Python requests library. It's a beautiful piece of software that makes dealing with HTTP requests easy. Testing that you're making the correct HTTP requests is not straightforward, though.

  • You can use the built-in python mock library. I won't reiterate points that have been made elsewhere but mocking usually leads to code smells.
  • You can use the responses library. It helps, but it becomes unmanageable quickly. It's challenging to set up expected responses, especially since there could be multiple per test. Additionally, it seems that it is unmaintained. I have run into bugs around passthrus and random test ordering.
  • You can use another third party testing library. I don't have experience with them and settled on building a personal one.

At work(PrintWithMe) we have multiple internal libraries. For any new one added, we make it a habit to provide testing functionality, including fakes/doubles, fixtures, setup/teardown, and other helper functions.

Top comments (0)