What is a reasonable code coverage % for unit tests (and why)? [closed]

This prose by Alberto Savoia answers precisely that question (in a nicely entertaining manner at that!): http://www.artima.com/forums/flat.jsp?forum=106&thread=204677 Testivus On Test Coverage Early one morning, a programmer asked the great master: “I am ready to write some unit tests. What code coverage should I aim for?” The great master replied: “Don’t worry about coverage, just write … Read more

When should I mock?

Mock objects are useful when you want to test interactions between a class under test and a particular interface. For example, we want to test that method sendInvitations(MailServer mailServer) calls MailServer.createMessage() exactly once, and also calls MailServer.sendMessage(m) exactly once, and no other methods are called on the MailServer interface. This is when we can use … Read more

How deep are your unit tests?

I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence (I suspect this level of confidence is high compared to industry standards, but that could just be hubris). If I don’t typically make a kind of mistake (like … Read more

What’s the difference between faking, mocking, and stubbing?

You can get some information : From Martin Fowler about Mock and Stub Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what’s programmed in for the test. … Read more