API-schema-based testing with schemathesis

Automatically generate test-cases based on your API-schemas.

Alexander Hultnér

APIs RESTful Test Libraries (pytest/nose/...) Testing Web Servers and MicroFWs (Flask/Tornado/Nginx/...)

See in schedule Download/View Slides

The goal with this talk is to introduce the audience to property-based testing for API’s using schemas to automatically generate test scenarios, enabling them to write more powerful tests faster.

The talk will focus on a subset of the field of property-based testing where we focus on testing by automatically generating properties and test strategies from the API Schemas that we often already have. These tests ensure that our APIs conform to their specified schema and enables us to write a much larger amount of tests in less time.

I will focus on the schemathesis library which leverages the strong hypothesis library as well as the hypothesis-JSONSchema extension strategies, and will in the future also support GraphQL via the hypothesis-graphql strategies. I’m a contributor to schemathesis and currently working on the future GraphQL support with schemathesis creator, Dmitry Dygalo.

I will also compare it with its predecessor “swagger-conformance”, pure property-based testing through hypothesis, schema strategies with hypothesis-graphql and hypothesis-jsonschema, and discuss their advantages and disadvantages. I will also briefly talk about “QuickREST: Property-based Test Generation of OpenAPI-Described RESTful APIs” (https://arxiv.org/abs/1912.09686), the research paper that’s part of the inspiration for these tools.

By focusing on property-based test generation using schemas we already have, I will show that a field like property-based testing, which can seem quite daunting at first, actually can have a low barrier to entry while yielding large amounts of value in return and is useful for most common web projects today.

The talk will show how formal schemas for APIs can and will continue to provide additional value outside the scope of documentation.

Type: Talk (30 mins); Python level: Intermediate; Domain level: Intermediate

Alexander Hultnér

Hultnér Technologies AB

Alex is a freelancing consultant who's currently in the process of building a company. He's been hacking on hardware and software since early childhood always loved solving problems. He started using Python seriously 2015 and it's been his main focus ever since.

Alex has previously spoken multiple time at PyCon SE and at the Gothenburg python user group GothPy, but also at other conferences and events such as Foss-North and Python Pizza.