Chapter 9. Testing the Book Shelf Application

Testing is a critical component of any software development project. One of the best results of the rise in popularity of agile development is that it has brought unit testing to the forefront of software development. More developers regularly write unit tests today than at any time in the history of software development.

With Rails, you have no excuses not to write tests. Rails makes it easy to write and execute tests for your Rails applications. The framework comes with integrated, automated testing tools built-in. Rails provides you with the tools to write unit, functional, and integration tests. You'll use unit tests to validate your model classes. Functional tests allow you to test your controller methods and verify things like responses, redirects, and HTML. Integration tests allow you to test your application from the user's perspective. Integration tests cover multiple controllers and navigation across pages.

This chapter will introduce you to all of the testing capability that is built into Rails, along with some that is not built-in but is extremely useful. In this chapter, you will write tests for the Book Shelf application that was developed in Chapters 6, 7, and 8.

Why Test?

All too often in the past, developer testing was left to the end of a project, and then only minimal testing was done. For the most part, application developers relied on Quality Assurance (QA) teams to test their applications when the coding was complete. ...

Get Ruby on Rails® Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.