13. Anatomy of a test
# Given some test accounts
➊ Setup account_1 = Account.new(100)
account_2 = Account.new(50)
# When I transfer money
➋ Act transfer(20, from: account_1,
to: account_2)
# Then the balances should be updated
➌ Assert account_1.balance.should eq(80)
account_2.balance.should eq(70)
16. A good test…
• Expresses the programmer’s intent
• Gives confidence that the code works
17. A good test…
• Expresses the programmer’s intent
• Gives confidence that the code works
• Only tests one thing
18. A good test…
• Expresses the programmer’s intent
• Gives confidence that the code works
• Only tests one thing
• Gives clear failure message
19. A good test…
• Expresses the programmer’s intent
• Gives confidence that the code works
• Only tests one thing
• Gives clear failure message
• Is independent of other tests
32. How do I start?
• Greenfield project? JFDI! Otherwise…
33. How do I start?
• Greenfield project? JFDI! Otherwise…
• Automate highest value tests first
34. How do I start?
• Greenfield project? JFDI! Otherwise…
• Automate highest value tests first
• Important features
35. How do I start?
• Greenfield project? JFDI! Otherwise…
• Automate highest value tests first
• Important features
• Where the most bugs occur
36. How do I start?
• Greenfield project? JFDI! Otherwise…
• Automate highest value tests first
• Important features
• Where the most bugs occur
• Use TDD for new features
37. How do I start?
• Greenfield project? JFDI! Otherwise…
• Automate highest value tests first
• Important features
• Where the most bugs occur
• Use TDD for new features
• Add tests for bugs when they’re found