dwyl / book

📗 Our Book on Full-Stack Web Application Development covering User Experience (UX) Design, Mobile/Offline/Security First, Progressive Enhancement, Continuous Integration/Deployment, Testing (UX/TDD/BDD), Performance-Driven-Development and much more!
https://dwyl.github.io/book/
820 stars 133 forks source link

Does 100% Code Coverage Mean my Code is Perfect? #21

Open nelsonic opened 9 years ago

nelsonic commented 9 years ago

yes, this is a click-bait question... :wink: obviously we can write poor code and still test it and get coverage...

insert example ...

But... we like to think of code coverage in a packaged food analogy: Imagine you are at the "health food store" and you see tasty-sounding words on a new product: "Vegan, Raw, All-Natural Delicious, etc..." however, no ingredients are listed. You ask the store assistant: "can you tell me what is in this...?"
she replies: "oh, just avocado, nuts and a dash of formaldehyde" _Formalda ... WHAT?_ you exclaim as you prepare to leave the store!! Yes, formaldehyde is a naturally occurring organic compound, which has been used by bad companies to extend the shelf life of "food" see: http://en.wikipedia.org/wiki/Formaldehyde#Contaminant_in_food

We (used to!) eat packaged foods all the time and trust the manufacturers to have our health and best interest at heart... but unless we know everything that goes into those products, and the precise process by which they are produced, we have no idea what we are consuming!

SOSANA commented 9 years ago

@nelsonic awesome analogy +1

simonmcmanus commented 9 years ago

Some nice click bait :)

U make a good point but It does raise some questions...

What level of coverage would u suggest aiming for?

Should front end code and backend code have the same level of coverage? What might be the difference.

What can I do to improve the correlation between high coverage and good code/tests?

When should I ignore coverage reports and exclude lines of code?

How you can use tools like Istanbul to write better tests and have a more robust application?

I'm Particularly interested in workflows used here.

How does coverage work with TDD?

nelsonic commented 9 years ago

You've got to love a bit of click bait! :wink: 100% code coverage is a minimum. Anything less and you are guaranteed to have bugs. What's more less than 100% coverage is a clear indication that tests have been written retrospectively instead of before the code... The best book on TDD I've read was: http://www.amazon.co.uk/Growing-Object-Oriented-Software-Addison-Wesley-Signature-ebook/dp/B002TIOYVW which is all about test-first development. Sadly is very heavily JAVA-focussed...

Istanbul & Blanket are the test-driven-developer's best friend! And I will introduce it in chapter 2 fo sho!