DEV Community

Joel Lau
Joel Lau

Posted on

1

Testing External Systems (TDD)

Software developed seldom works in isolation.

Connecting to external systems such as databases and consuming 3rd party APIs are integral parts of many products made today.

However, how do we write tests for these BEFORE we write code that integrates with these external systems?

Top comments (2)

Collapse
 
brandinchiu profile image
Brandin Chiu

If you're writing unit tests for TDD, then you would be responsible for "mocking" these integrations as external services.

Your unit tests are meant only to verify the internal integrity of your units or functions, not the external services.

Usually this means making assumptions in your tests, and then testing for several things.

For example, if you wanted to test how one of your methods interacts with an external service, you would want to "test" things like example responses based on those assumptions.

Or you'd want to test how your method works if you were to simulate a failure from the api.

stackoverflow.com/questions/266581...

Collapse
 
shanif profile image
Shani Fedida

I don't think the answer is different for TDD and writing tests in the end. You need a way to provide the dependencies: usually with fakes.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay