How to cover testing in Rails applications already completed?

Asked

Viewed 181 times

-2

TDD is usually used during development. But what about when you walk into a company, get the code all messed up and see the urgent need for improvement and of course, test coverage? How to proceed? How to test if all functionalities are implemented and functional?

  • This question has no answer! 100% coverage is crazy even when planned from the start. All you can do is write the tests slowly, starting with what gives you more trouble.

  • @user15694 Welcome to Stack Overflow! Could explain better, preferably by providing facts and data?

  • I also think there is no answer, what I would do is, create the tests for the main features of the application, so I could start developing and refactoring without having major headaches.

1 answer

3

I’ll try to leave some tips here:

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

  • Avoid testing code from external libraries only, or from the library itself framework. Test the your code. Activerecord validations, for example, have already been tested by the developers themselves. (Click here and look at the "test" folder there).

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

  • Testing views (HTML and Javascript) is complicated, and should be avoided in simple cases. That is, unless there is code undocked from views. Some framworks, Like Angularjs, they have their own ways of testing, although it seems very "challenging" compared to the simplicity and configuration of Minitest.

  • This isn’t just about testing. In some cases it is important to create your own classes, that is, classes that are not controllers or models, but contain logic used by them, to make the code more "clean" and easier and legible and also tests. It is good to remember that just as it is important to know Javascript and not only jQuery, it is also much important to know Ruby very well, and not just Rails. This helps you define the right architecture for 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 application on Rails. Who Seeks Finds.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.