You are here

Building Your Own Api Testing Framework with Pytest and Requests

APIs lend themselves extremely well to test automation. There's a simple reason for this: APIs are designed to be consumed by computers, not by people. So where with UI tests, you need to rely on testing-specific libraries such as Selenium WebDriver, with API testing you can simply use the same libraries as the ones that are used to build applications. This also means that building an API testing framework is significantly easier than building one for UI testing. So why let's not just do that in a tutorial?

You'll be able to experience how easy it is - assuming you have some very basic general programming knowledge and know what an API is. We'll build our framework using Python, Pytest and the requests library. More importantly, we'll explore and discuss what your framework needs to be able to do to support the full life cycle of a test suite. Because I see all too often a focus on how easy it is to build tests and little mention of maintainability or readability of test results.

After this tutorial you'll have a basic API testing framework you can extend (I will be giving tips for next steps). More importantly you'll have a better understanding of testing frameworks in general. And that will come in handy when you have to evaluate a testing tool, or when you are discussing a framework with the developers that build it.

Takeaways

  • How to make your framework support the full life cycle of a test suite (inc. menomonic)
  • Basic programming skills applied to Python, pytest and the requests library
  • Inspiration to build their own tests and frameworks through programming