Adding tests to an existing app

If I have a rails app without test but fairly with many controllers, models and views and now I start writing the tests where should I start from?

Since the app is working how can go I from integration tests to unit testing because from what I understand is that you first start writing the tests which show you a way and then use that to make the tests go green, but in my case how can I do that?

You should read Michael Feathers book “Working Effectively with Legacy Code”. If you don’t have enough time to sit down and plow through a book, here is a 12-page article with the same title that has some nuggets in it: Vacation Rental Hacks.

1 Like

Nice, link, @dolphorama; thanks!

If you’re adding new features than start writing tests for them first and slowly cover some bits of legacy code here and there along the way. It will make more sense where to go after that.
Or if you just need to cover existing code with tests start from public facing methods, controllers for example, and then move down the chain(models → helpers → etc.)

In these situations, I find it useful to write characterization tests first. These are especially useful when they cover functionality that interacts with whatever feature you’re about to work on. Once you have a characterization test that covers the existing behavior (regardless of whether the existing behavior is correct or not), your new feature can be test-driven with some degree of confidence that you’re not breaking existing functionality.