Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Marty Hitchcock
13,108 PointsWriting Tests
I am in the early stages of learning ruby on rails and am struggling to figure out why we are writing tests. To me it seems easier to just test the features manually.
Is there some added bonus from writing a test instead? Or is it just that we are being taught the concept with simple ones that wouldn't normally require tests?
1 Answer
Stone Preston
42,016 Pointsit is not easier to test the features manually.
say you have a contact form that the user enters some info in. its got a email and a message body field. you can test that just fine manually and it wont take you long at all. so you dont write any tests. you do it yourself and make sure your validations are working. it works great. cool. then next week you have to add a phone number field so you have to go back and test ALL the fields again to make sure you didnt break anything you did before. then a few days later you have to add another field, and you have to test everything manually again. Now multiple this by 5 since you have added 5 other forms on your site since that first contact form and it goes on an on.
tests make it easy to verify your code does what its supposed to (not just forms). It also saves you time and headaches. testing that form manually after each change would have wasted a lot of time when the test does it in 3 seconds. TDD also helps you formulate how you need to make things work. there are many advantages.
that being said, EVERYTHING probably doesnt deserve a test, and its up to you to decide if you want to or not. Also TDD follows a write tests first, write code later methodology, but it might not be necessary (or even possible) to write a test first before implementing the code. sometimes you just need to build some exploratory code to flesh things out.
Marty Hitchcock
13,108 PointsMarty Hitchcock
13,108 PointsThanks! Great explanation.