4 ms·
I spent more time building my mocks instead of building my tests. Sometimes a file might have 90% mocks and 10% tests. Or maybe that's just my mocking framework
by CMCDragonkai 12y ago
I spent more time building my mocks instead of building my tests. Sometimes a file might have 90% mocks and 10% tests. Or maybe that's just my mocking framework...
- glenjamin 12y agoThe idea is that if you end up with code like this, it shows you have too many collaborators and should refactor them away.
- oelmekki 12y agoExactly. An other reason could be it's a main entry point for code execution, a class that only purpose is the glue others. In that case, having a lot of mocks is a code smell pointing that you should probably test this on the integration level rather than on the unit one (and thus, discard mocks and use "real" everything). (but beware not to be too much self indulgent on what is a gluing class, most of the time, they are not and it's indeed a god class problem).
- edgyswingset 12y agoIt could just be that the module of code under test doesn't do enough. If you need to mock a service, database, other service, error-handler, etc ... but the core logic is just verifying that <some condition> is met, then this is going to be the case. Personally I like to avoid mocking for cases like this, since integration tests can usually suffice. As you said, though, it could also be the framework. If you're in C#-land, Moq is pretty terse with the syntax so the actual mocking code isn't that big.
- CmonDev 12y agohttps://github.com/FakeItEasy/FakeItEasy https://github.com/FakeItEasy/FakeItEasy