Chapter 8: Testing FastAPI Applications
In the last chapter, we learned how to secure a FastAPI application using OAuth and JSON Web Token (JWT). We successfully implemented an authentication system and learned what dependency injection is all about. We also learned how to inject dependencies into our routes to restrict unauthorized access and operations. We have successfully built a secure web API that has database support and is able to perform CRUD operations easily. In this chapter, we will learn what testing is and how to write tests to ensure that our application behaves as expected.
Testing is an integral part of the application development cycle. Application testing is done to ensure the correct functioning state of the application and easily detect anomalies in the application before deploying to production. Although we have been manually testing our application’s endpoint in the last few chapters, we will be learning how to automate these tests.
By the end of...