2
votes

I learned Rails to create a website and the basic version is up and running. Unfortunately, I only wrote a couple of tests for my code. What should I do now to get test coverage for my code? It will be difficult to go back now and write tests for all my previous code. Would it make sense to use a recording tool like Selenium to visit the sites and record tests? Is there a specific recording tool for Rails?

(In short, how can one catch up to get test coverage on code that doesn't have enough tests?)

2

2 Answers

1
votes

First, quantitatively measure your test coverage with a tool like rcov.

You're right that integration tests will provide more coverage, so they are the right choice for your goal. However, they provide less meaningful feedback when they fail, so you'll want to augment or replace them with more isolated tests in the future.

I expect that recording tests will result in a test whose source is hard for humans to read. So, you might want to consider capybara-webkit instead (but don't use capybara 2.1 yet).

Finally, because your current testbase is small, you have an opportunity to consider rspec or shoulda-context.

0
votes

Truth is, you're going to just have to go back and right all the tests.

First of, no kind of "recording" tool would help with the unit and controller tests.

Second, if you did use something to "record" feature/integration tests, what exactly would you be testing? If you aren't specific to what functionally you expect to be there, how can you be sure your app is even doing now what it's supposed to be doing?