unit testing - How are Mocks meant to be used? -


when introduced mocks felt primary purpose mock objects come external sources of data. way did not have maintain automated unit testing test database, fake it.

but starting think of differently. wondering if mocks more effective used isolate tested method outside of itself. image keeps coming mind backdrop use when painting. want keep paint getting on everything. testing method, , want know how reacts these faked external factors?

it seems incredibly tedious way advantage seeing when test fails because screwed , not 16 layers down. have have 16 tests same testing coverage because each piece tested in isolation. plus each test becomes more complicated , more tied method testing.

it feels right me seems brutal kind of want know others think.

i recommend take @ martin fowler's article mocks aren't stubs more authoritative treatment of mocks can give you.

the purpose of mocks unit test code in isolation of dependencies can test piece of code @ "unit" level. code under test real deal, , every other piece of code relies on (via parameters or dependency injection, etc) "mock" (an empty implementation returns expected values when 1 of methods called.)

mocks may seem tedious @ first, make unit testing far easier , more robust once hang of using them. languages have mock libraries make mocking relatively trivial. if using java, i'll recommend personal favorite: easymock.

let me finish thought: need integration tests too, having volume of unit tests helps find out component contains bug, when 1 exists.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -