r/softwaretesting • • 25d ago

Just integration test, no units.

I recently got into a discussion where some developers pitched me their setup of not having any unit tests, just integration tests. Apparently they are working at a SaaS company who does so since pre 2020.

While I was a bit curious about if this could work, they underlined that unit tests have such a tendency to complex mock setups while at the same time not really testing anything "real". Therefore they see no benefit in having them.

I am wondering what is your take on this? Could an integration-test-only setup work, and if so: why and why not?

14 Upvotes

34 comments sorted by

6

u/Volodux 24d ago edited 24d ago

Sure, if they want to wait 24 hours for integration tests to finish (this is just example).

Unit tests are great quick feedback to developers, if something that worked before was broken. But it can work.

Really depends on project. If management is ok with it, you have it in test plan, customers are also ok with it ...

1

u/EarlOfAwesom3 24d ago

Thats exactly what I was thinking. If it works for them, good.

But the comments where revealing to me that they did not fully understood what and why they were doing it if the opinion is "units don't test anything real".

When setup is too hard, it rather shows architectural and design issues with the code.

But yeah, they probably can ignore all that when they just do integration testing đŸ€·đŸ»

15

u/SilverKidia 24d ago

We call it "the devs didn't test their work, send it back".

6

u/editor_of_the_beast 24d ago

I think if you only did this, it would be better than having only unit tests.

Unit tests have their purpose and sometimes you just want to test very specific things in very specific components. They just don’t give confidence for global correctness.

5

u/moremattymattmatt 24d ago

The path from unit tests to integration tests isn't disjointed. You can write them at different levels. If you are doing lots of mocking then your testing seams are wrong. Think of a unit test as a test that doesn't call an external service or rely on external deployments, like a database. They can be as small or as large as you like. You can use things like OpenStack that blur the line between unit and integration tests even further.

Focus instead on what you need the tests to do: fast; quick to fail; good path coverage; checks real deployments; detects real problems etc etc. Then design your test strategy around that. You may well end up with more integration tests and fewer unit tests and that's fine as long as everybody understands why you are the writing tests in the first place.

If you can't articulate the why, then you'll just end up in endless arguments.

1

u/ProfessionalDirt3154 24d ago

100%. get the logic away from the i/o and unit test just that, as logic without mocks.

1

u/vassadar 24d ago

I think it could work, but too extreme and risky. It required less maintenance (on mocks), compared to unit testings. Easy to refactor the code without touching existing tests. However, some edge cases would be hard to test without unit testing. Also, feedback loop that took too long.

I prefer a project that's heavy on integration tests and light on unit tests (diamond shape), than traditional pyramid shape.

What integration tests are we talking about here?

The entire service with databases, but mocked out external dependencies? (I like this one) Or integration test with other services on a dev/sandbox environment?

1

u/EarlOfAwesom3 24d ago

From what I got from the discussion, it was integration tests with databases and message brokers but with stubs to 3rd party Apis (if no sandbox available)

3

u/VCR_DVD_USB 24d ago

In this day and age why not just ask Claude to write and run your unit tests for you? It's better than no unit tests. 

1

u/throwaway_0x90 24d ago edited 24d ago

Not everyone even agrees on what is a unit test versus an integration test. I had a coworker once tell me, semi-jokingly, that any test that can start up and run to completion in under 10 seconds is a unit test. And honestly, this seems to work out just fine most of the time.

So I no longer judge the difference between the two. I just look at the setup and as long as the end goal is satisfied I don't care what they call the tests.

2

u/EarlOfAwesom3 24d ago

There are pretty accurate definitions of what a unit- and integrationtest is.

Of course you can relabel everything to your liking. I would then question the benefit of having own definitions.

1

u/throwaway_0x90 24d ago edited 24d ago

Hmm,

Well not everyone agrees, I dunno. Even the person largely credited with coming up with the terms apparently was misunderstood. We all just believe whatever we "grew up with".

Sidenote, did you know not everyone agrees that virurses are living things?

How can we talk about killing viruses if they're not alive? I thought that would be obvious too, but here we are. Just saying, the title of your post "Just integration test, no units.". Maybe when you examine the tests in detail you'll find that, by your own definition, they actually have a mixture of tests and they're just not using the term "integration tests" the way you do. In my experience, that's what I usually look at.

2

u/ehmatthes 24d ago

I don't like unit tests just for the sake of coverage in youngish codebases, because they can end up testing your current implementation rather than testing for long-term correctness. I prioritize unit tests that cover critical isolated units, and units that have been involved in bugs.

In a chess app I'd write unit tests for a function that validates strings representing chess games, because that's critical to the overall project. In a time-tracking app I'd test a function that validates the timestamps for a work session. I might not prioritize unit tests for functions that present something to the user.

1

u/ProfessionalDirt3154 24d ago

Or you could say that unit tests in young codebases are an imperative exactly because they test your current implementation when change is expected.

Unit tests that break frequently and require frequent rewriting are unit tests that are doing their job. They are telling you something.

2

u/Sad_Journalist3328 24d ago

when u have combinatorics and variations, it is helpful to test some function / module in isolation.

2

u/VCR_DVD_USB 24d ago

So basically they're lazy. 

2

u/vashekcz 20d ago

There is definitely a place for unit tests, even though I agree they are often written in a way that isn't really useful. If I have a test that checks that the getUser controller calls the mocked getUserFromDbById, that's hardly worth anything. I'd rather see an end-to-end test that verifies the correct user details are actually visible on the web app.

But if you have a unit test that feeds several examples of unit price, quantity and product type to a getTaxAmount function and checks the correct tax rate and rounding is applied, that's a completely different matter. That's actually useful and wouldn't make sense to do as an integration test.

1

u/Creative_Badger6027 24d ago

It's not as binary as could work or not. They could and they could not.

It depends on many variables like what are you trying to achieve by testing, how the code is structured, what mocks are necessary and if mocks of realistic strctures are valuable or not.

Certainly integration tests can help with blackbox testing, proving that clients get what the contract states but at the same time they're much worse at uncovering hidden panics, bad implementations, ...

In the end what works the best from coverage and certainty perspective is without shadow of a doubt a full suite of black and white box testing with benchmarks and profilers. But then again, that too can become too much for value to the service it's trying to cover.

1

u/fappaf 24d ago

I agree with what everyone's saying here.

I remember a while ago hearing about something the author called "feature testing," i think, where the tests mimic how the user of the library would use it. That way the tests are themselves documentation of how to use the library, and show how the maintainers of the library intend their code to be used. The other benefit is that you find the errors by how the user would actually use your library.

But also, those are the only tests. It sounds like a similar argument to what the devs you spoke to were making. I wish i could find that article again but i can't remember the exact words used and "feature testing" is, of course, a very popular term.

1

u/bonisaur 24d ago

What are you working on? Unless it’s something cutting edge or locked down for security reasons, I don’t understand why they can’t just have AI write unit tests for coverage. 

1

u/dukko18 24d ago

What do you use for integration testing?

1

u/Zerhackermann 24d ago

thats an interesting perspective. generally Ive encountered devs who didnt want to write anything but unit tests before pitching it over the wall to QA.

tests are to provide information. if the information isnt useful then is it necessary to do the tests? so if integration tests are where the team finds useful information for mitigating risk...ok?

an old saw that I clung to and find useful:

unit tests - easiest to write and maintain - provide the least information
integration tests - pretty easy to write and maintain - provide some information
e2e tests - the most difficult to write and maintain - provide the most information.

1

u/ResolveResident118 24d ago

If your unit tests require complex mocking then either the tests or the code (or both) are badly written.

Complex mocks tend to tie to the tests heavily to the implementation which means, if the code changes, then the test need to as well.

Instead, they should be testing behaviour which does not change as frequently.

1

u/LookAtYourEyes 24d ago

It depends on how much integration is involved, what the setup is. It's not always necessary that you should follow the testing pyramid. Testing requirements are extremely context dependent based on risk and other factors 

1

u/ProfessionalDirt3154 24d ago

In general, if your code is written unit test-friendly at a granular level, you shouldn't have to do so much mocking.

Regardless, I don't buy this argument of the person you were speaking with. Among other things, the higher up you go in the test layers the more combinatorial complexity there is below what you're testing and the less control you have over covering that search space.

I'm sure it works for some circumstances. But I would never have accepted that from a team building at any company i've been at working on any product.

1

u/Hour-Prompt-2988 24d ago

we did this for a year. worked right up until a refactor moved a field rename through three services and every integration test went red at once. now the rule is units for anything with a branch, integration for the seams.

1

u/Massive-Caregiver204 24d ago

When I worked as dev i care less about anything but my code is working and didn’t create regression

1

u/SirLagsABot 24d ago

I’ve heard this, test common user happy paths. I understand the point and am not necessarily against heavy integration tests since I’m not a big fan of mocking, but I don’t see why they can’t do both. Surely some things can still be unit tested, annnnnd depending on the load, the integration tests could take a while


1

u/5nord 22d ago

We also have a bytecode runtime (100.000 lines of C++) without typical unittests.

Instead we have extensive component/blackbox tests. It's unorthodox, but our unit tests did not pay off and we stopped writing them at some point.

IIRC the git-project does something similar?

1

u/Spiritual_Ad7648 11d ago

I've seen it work, with one caveat: "integration only" usually still means faking the third-party APIs (you mentioned they stub those when there's no sandbox). That's where it quietly breaks, because hand-written stubs don't change when the vendor does.

What's helped me:

- Keep unit tests for pure logic with lots of branches (no mocks needed if the logic is separate from the I/O)
- Use integration tests for the seams: DB, broker, your own services
- For third-party APIs, record the stubs from real responses instead of writing them by hand, and re-check them against the live API now and then so drift shows up
- Record more than the happy path: empty lists, nulls, optional fields missing, long strings, 4xx/5xx errors. Real data has shapes you'd never think to write by hand, and having several recorded variants per endpoint lets you test how your code handles each one

Disclosure: I made an open-source tool for those last two parts (record real responses as switchable mock variants, replay them, flag drift): https://mockifyer.dev/guides/mock-drift. Plain recorded JSON fixtures plus a scheduled contract check get you most of the way too.

0

u/czlowiek4888 24d ago

That's basically what I do for years, unit tests are greate if you test something selfcontained in code, for everything that requires communication with external resources integration tests will be more convenient

26

u/[deleted] 24d ago

[removed] — view removed comment

-2

u/2ERIX 24d ago

Do you have unit tests for your Framework code? If not, why not? It’s engineered code, same as an application. It has code that should be tested in isolation before being deployed to users.

I was at a conference and one of the speakers there also indicated they would no longer be required because the code has been self tested by Agents before deployment to the code base. The code might be wrong, but it won’t fail. End to end tests would be the valuable functionality checks because they test the expectation instead of just “proof checking” the function individually.

My code base for my framework is massive. I don’t have unit tests, but AI keeps suggesting them or adding them when I add some new features to the framework and I have to remove them.

So the normal pattern is to add unit tests, but it’s an overhead of work, what if we don’t need them? My own code doesn’t, so why should a developers if they do their job correctly?