Adding Tests to Legacy Rails Apps

Evan (Rabble) Henshaw-Plath, Hacker, Independent

Adding tests to legacy rails apps

Do legacy apps exist - rails < 3 years old!

"Who has time for tests?"

Testing == Health Food - good for you but not yummy

Testing == debugging!

Don't do it all at once - you won't pull it off.

Create test database

Use migrations

Scaffolded tests don't work... need to fix them first

Find a bug - write a test;

step by step Refactor a method - write a test

Test one thing at a time - short 3-5 line things (one assertion)

Running tests - rake or directly

GOOD IDEA: use development.log to build tests (has parameters, sql, etc.)

Test coverage

rake stats rcov - amazing tool, good graphs

other tools: heckel

autotest - great testing tool for immediate feedback

Fixtures, mocks, pull from database, all have pros and minuses

zentest..?

Heckle: Take Your Tests' Lunch Money

Kevin Clark, Powerset "

Mutation Tester"

Randomly permutates your code, then... runs your tests.

If tests don't fail, code is useless, or no tests are written.

heckle SomeController -> output is list of mutations that passed the tests.