Hacker News new | ask | show | jobs
by hypeatei 973 days ago
What is the alternative specifically for unit tests?

You can create integration and e2e tests that aren't as sensitive but I don't really understand what people are suggesting when they say mocking is bad in unit tests.

2 comments

First: drop e2e, unit, etc distinction

It is irrelevant and driven by some testing evangelists

Tests are either quick or slow and may touch external stuff, thats mostly it.

Whats wrong with mocks? If they lead to scenarios where your tests are green, but app doesnt work then it sucks. Ive witnessed projects with all green tests but app wasnt even waking.

I think there is an evolution developers go through. Right around the "design pattern" stage where everything is decoupled, hinges for all parts. Devs seem to focus on the test coverage value. Both these attributes stem from the same failure to understand the underlying business. The model rarely reflects the actual business needs (usually because the dev spends more time reading about, and thinking about tech as opposed to understanding the business) they use flexibility in the codebase as a fallback because gee the business can be anything. Code coverage equally fails because they only think about their code. Sometimes the most useful thing is a business case that was never thought about. It's code that doesn't exist. Perfect code coverage won't tell you anything about code you haven't written.

I'd rather spend time trying to learn the business, and where it's going, and why my product is useful, than mocking out some dumb part I can test a few times manually. Unit tests are super valuable tool, but not everything needs a unit test.

People downvoting you don’t do testing and are upset.
They test mocks.
> I don't really understand what people are suggesting when they say mocking is bad in unit tests.

"Unit test" does not necessarily mean "class test" or "method test"

and always treating it as such is counterproductive.

I have done it both ways. tests coupled to every public method with dozens of mocks would not be my preference.