Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"don't mock"

How are you meant to write a unit test for a class without mocking out external dependencies? Wouldn't that make it an integration test?




Not the OP but I count integration testing as testing integrations /between/ systems - wherever your code depends on something outside your codebase. You can mock this for unit testing.

Don't mock things that are already in your codebase. Use the actual object.

Common argument against this I've heard is "But then when something goes wrong it is harder to figure out where the problem is" - I have never actually experienced this myself, but I have, very often, experienced being reluctant to do any refactoring because I'd have to rip up all the unit tests because they are testing only implementation details




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: