11 Testing Streamlit apps

 

This chapter covers

  • Developing a testing strategy for an application
  • Differences between progress unit, integration, and end-to-end tests
  • Writing and running automated tests using pytest
  • Using Streamlit's AppTest to create a running app with simulated user interactions
  • Evolving your tests alongside your code

You've spent hours building your Streamlit app. The UI looks great, the code runs smoothly, and you're ready to share it with the world. But what happens when a user suddenly enters unexpected data? Or when the API you're calling changes its response format? Or when you deploy an update that inadvertently breaks existing functionality?

Without proper testing, your elegant application can quickly transform into a frustrating experience for your users. As the saying goes, "Untested code is broken code"—a sentiment that applies as much to Streamlit apps as to any other piece of software.

11.1 MovieScout: An app to test

11.1.1 Using the TMDB API to pull movie info

11.1.2 The backend

11.1.3 The frontend

11.2 Testing our application

11.2.1 Different kinds of tests

11.2.2 Our testing approach

11.2.3 A quick introduction to pytest

11.3 Unit testing the backend

11.3.1 How unit testing works

11.3.2 Writing unit tests for the backend

11.3.3 Running our tests

11.4 Unit testing the Streamlit frontend

11.4.1 Writing unit tests for the frontend

11.4.2 Running our frontend tests

11.5 Testing the integration between components

11.6 Testing the end-to-end flow

11.7 Evolving your code and tests

11.8 Summary