Open Al3xDo opened 2 months ago
@Al3xDo Hmm, why did you create a test for the repository? I believe you should focus on creating unit tests at the service layer, where you can mock all dependencies of the service.
However, if you need integration tests, you can consider using Testcontainers. It's simple to use and performs well.
Hi @vuxmai , I think the repository should be tested as well if that function includes some logic/conditions. In the example code above, you can see it has the condition inside the repository function:
if limit > 12:
limit = 12
you may think that we can have the integration test to cover that but for me, the integration test has some drawbacks:
I think testing the SQL query generated by the repository function is not only covering all the logic but also fast, and does not require external running service (mock db instance).
Hi everyone,
I want to test the query string generated by the repository function only. My goal is to make the unit test as independent as possible and avoid creating a dedicated database instance during testing.
Here's what my code looks like:
However, I encountered this error:
I've tried many ways but could not resolve the issue.
Here is the function that I want to test: https://github.com/teamhide/fastapi-boilerplate/blob/ca3bb3fa5686cb031d6cd99d45b34fd7d2b12494/app/user/adapter/output/persistence/sqlalchemy/user.py#L8-L27