Testing Antipatterns <ul><li>Matt Robinson </li></ul><ul><li>Puppet Labs </li></ul>
Anti - What?
Antipattern ( Dark Pattern ): <ul><li>A pattern that is commonly used but is ineffective and/or counterproductive </li></ul>
Who has an extensive test suite?
Who feels like they should test more?
Who dislikes, even dreads, writing tests?
Testing Can Be Fun Text Text Text Text http://xkcd.com/583/
Red Green TDD Addiction
Testing Framework Games (although these can be a distraction) (although these can be a distraction)
Not looking like an idiot - that’s fun right?
Why Automated Testing? <ul><li>Prevents regressions </li></ul><ul><li>Improves confidence </li></ul><ul><li>Documents requirements </li></ul><ul><li>Catches errors before codes ships </li></ul><ul><li>You fill in the blank _________ </li></ul>
Overheard Reasons Not to Test <ul><li>Don’t trust the tests </li></ul><ul><li>Who tests the tests? Quis custodiet ipsos custodes? </li></ul><ul><li>Makes refactoring harder </li></ul><ul><li>Not enough return on investment (ROI) </li></ul><ul><li>Too hard and/or time consuming </li></ul>
Antipatterns that have bitten me the most
Not Running Tests Often Enough
If it’s Hard and Important Do it More Often
testing, deploying, releasing, exercising, meditating, writing, public speaking
How Often? <ul><li>Before deployment or release </li></ul><ul><li>After every commit: CI (Continuous Integration) - Jenkins, Cruise Control, BuildBot, Cerebrus, CI Joe </li></ul><ul><li>Before every commit (or push): discipline, git hooks </li></ul><ul><li>Every save: autotest, watchr </li></ul>
Not Fixing Broken Tests Before Committing New Code
How Slow Is Too Slow?
Unit Test Suite Took 8 Hours to Run - On One Project
Single Test Took 2 Minutes to Start
So slow that rewriting it in PHP would make it faster
How to Get Faster <ul><li>Make your implementation code faster </li></ul><ul><li>Run your tests in parallel </li></ul><ul><li>Optimize your tests (new framework, trick garbage collector, rewrite culprits) </li></ul><ul><li>Mark some tests as slow and only run them occasionally </li></ul>
Why mock when the real things will do?
Testing at the Wrong Level
unit, smoke, functional, integration, acceptance
Success Against All Odds (test never fails) (test never fails)
Testing Implementation Instead of Behavior
Order Dependent Failures
You’ve got too much global state
What are we testing again?
<ul><li>The Dodger - Never tests desired behavior </li></ul><ul><li>The Stranger - Misplaced tests </li></ul><ul><li>Local Hero - Worked on my dev box </li></ul><ul><li>Generous Leftovers - Fills your hard drive </li></ul><ul><li>The Giant - You may have a God object </li></ul><ul><li>The Loudmouth - Spams your test logs </li></ul>Other Antipatterns
Avoid Antipatterns and Testing Can Be Fun
Links <ul><li>http://blog.james-carr.org/2006/11/03/tdd-anti-patterns/ </li></ul><ul><li>http://jasonrudolph.com/blog/testing-anti-patterns-how-to-fail-with-100-test-coverage/ </li></ul><ul><li>http://blog.rubybestpractices.com/posts/gregory/034-issue-5-testing-antipatterns.html </li></ul><ul><li>http://c2.com/cgi/wiki?AntiPatternsCatalog </li></ul><ul><li>http://martinfowler.com/articles/mocksArentStubs.html </li></ul>
Ask questions whenever you want
Talk about Design Patterns general reusable solution to a commonly occurring problem
Realized while writing this talk that I was focusing on what pissed me off and made me not want to talk about it. Should be humor in testing.
Red failing Green passing
Not really an antipattern since it’s really only solving being lazy
CI essentially glorified cron job
The Joel Test #5: Fix bugs before writing new code Mention Lava Lamps
Martin Fowler Mocks aren't Stubs. Never met a mockist whose tests I liked. Not mocking means mini integration tests. Possibly controversial. When to mock: code you don't control - file system, web server, external libraries like ssl
Too much mocking might indicate this
Everyone has their own terms
Test Driven Development prevents this
Behaviour Driven Development is a larger term with more meaning
These are annoying but can’t be ignored. How to find these failures - binary search.
Testing antipatterns can indicate antipatterns in your implementation code
Data driven web apps tend to be even worse