How to give coverage for tests in completed Rails applications? [closed]

-2

TDD is usually used during development. But when you get into a company, pick up the whole code zapped and see the urgent need for improvements and of course, coverage of tests? How to proceed? How do I test if all functionalities are implemented and functional?

    
asked by anonymous 26.09.2014 / 22:17

1 answer

3

I'll try to leave some tips here:

  • It is impossible to achieve full coverage of tests. Make an analysis of what is most critical / gives you more work / needs refactoring, and start there.

  • Avoid testing code that comes only from external libraries, or from the framework itself. Test the your code. Validations of ActiveRecord, for example, have already been tested by the developers themselves. ( Click here and see the "test" folder there).

  • One great thing about Ruby / Rails is that it allows you to add / overwrite methods in pre-existing classes, both Ruby (as String class) and Rails (like ActiveRecord classes). This can be done by changing the class itself through mixins (in the case of ActiveRecord, for example) or in some cases inheritance (like the Rails FormBuilder class). Regardless of the method, it is advisable to write tests also in these cases. (to run all tests, even those in folders other than those automatically generated, use [spring] rake test:all )

  • Testing views (HTML and Javascript) is tricky, and should be avoided in simple cases. That is, unless there is undocked code from the views. Some framworks, such as AngularJS, have their own ways of testing, although it looks very "challenging" compared to the simplicity and de-configuration of Minitest.

  • This is not just testing. In some cases it is important to create your own classes, that is, classes that are neither controllers nor models, but contains logic used by them to make the code "cleaner" and easier and readable as well as the tests. It is good to remember that just as it is important to know Javascript and not only jQuery, it is also very important to know Ruby very well, not just Rails. This helps you fine-tune the architecture appropriate to your system.

  • Read, read, read, read and read some more. If you know English, do a Google search and you'll find great blog posts discussing good ways to test your Rails application . Who seek finds.

05.10.2014 / 18:51