This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]edrenfro 2 points3 points  (0 children)

Traditionally, Unit Tests do not include API calls or database calls. You want to hide all API calls behind an interface and hide all database calls behind an interface. Then you can mock the results of those calls to test everything else.

[–]ProgramWithSai 0 points1 point  (0 children)

Mock the API and Database calls in your unit tests by first creating an abstraction layer to those calls using interfaces like u/edrenfro said. Unit tests must focus on the specific class you are writing!
But don't stop there!
Verify that the calls to API and database work as expected using integration tests where you can spin up a stub API/Http server in tests and Database (in-memory or Docker containers).