Testing
For Testing¶
Test always is a part of developer when create featute follow to TDD progress.
FastAPI intergrate testing with pytest, httpx and some fake data generate tools like Faker
ref: FastAPI Testing
ref: Faker to create fake data
ref: Factoy Boy
Progress
Export the variable TEST_DATABASE_URI that is the connection string to Test Database. The database for testing purpose can be the database service in local development database in Docker.
Prepair working directory and the environment
then write your tests cases, with syntax of prefix test_*
then, execute the test
https://labs.flinters.vn/technote/thiet-ke-restful-api-nhu-the-nao/
Concept of Fixture of Pytest
ref: https://docs.pytest.org/en/6.2.x/fixture.html