79257593

Date: 2024-12-06 10:13:54
Score: 0.5
Natty:
Report link

In my opinion, it depends on your test strategy and goals. Each approach has pros and cons. Let's mention some of them.

  1. Query the database:

Pros: Reliable, independent verification.

Cons: It breaks API-Centric testing because an integration test usually focuses on the API's behaviors.

  1. Using the GET endpoint

Pros: API-centric (it allows you to test a complete workflow), More realistic (it reflects the behavior of the users using the APIs)

Cons: It is dependent and relies on another endpoint (as you already mentioned)

I prefer using the GET method instead of querying the database because an integration test is not about focusing on the internal implementation details like the database, but combining both approaches is possible (especially when you are not sure that the GET endpoint works correctly).

Steps to take for the combination approach: 1- make post request 2- assert response.status_code of the post request 3- make get request 4- assert response.status_code of the get request 5- assert whether the foo item is in the response body 6- query the database 7- assert foo item

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Mohsen Khosroanjam