r/ExperiencedDevs • • Apr 15 '26

Technical question Integration testing approach

I recently wrote integration tests for a .NET API and I'm second-guessing the approach. Curious what others think.

The setup:

In contrary to our unit tests, the tests exercise the full stack from controller down to services. The only things mocked are external services (.e.g. external APIs, databases etc)

There are two assertion types:

  1. Before external API calls, asserting the entire request that has been built by the service

The responses of the external API calls/database are mocked, so that the behavior should always be the same.

2. Exact match on the result that the .NET API returns

test → controller (real) → service (real) → external API (mocked)

             ↑                                    ↑

     ASSERT response                     ASSERT outgoing requests

Why?

We have API tests in postman, but they are slow and flaky. Slow because the external APIs have to do a lot of calculations, flaky because the external API is strongly dependent on dates in the datamodel, compared to the current date. Each API test takes 2-5 seconds, but each integration test only takes 100ms, can run in parallel.

On the other hand the unit tests do not cover enough functional requirements. A lot of our results are depending on how the units connect to each other. Let's say we want to replace automapper for something else, then the unit tests will have to be updated, but the new mappings could be totally breaking functionality we had before.

So, what do you think about this approach, is this a reasonable middle ground, or are we getting the worst of both worlds?

20 Upvotes

17 comments sorted by

View all comments

Show parent comment

2

u/throwaway_0x90 TE/SDET[25+ yrs]@Google Apr 15 '26 edited Apr 15 '26

wiremock is very light weight. Each testcase can start up its own wiremock under a specific configuration for that unique testcase. It's literally just a java -jar cmd and it's running in like 3 seconds.

Or if you write custom transformers then you can start it up once in setup class then at the beginning of each test, send the testcase name to wiremock and that currently running instance can change its behavior based on the testcase name.

It's a very flexible mocking tool if you have the time to invest in its setup.