Writing test cases (rspec) for an existing application

Being an rspec noob, I don't know this question makes sense. BUt I really got confused and could not get a solution for this.

We have one new requirement, asked us to write Rspec test cases for an existing project. They have an application with rails3 that already works, but they want rspec entries to be written now.

My question

Does writing Rspec cases for an existing application make sense?

Is it possible to write a specification for an existing project

Should we follow any recommendations for writing specifications for an already written application

thanks

+6
source share
3 answers

As dpassage correctly pointed out, your question has nothing to do with rspec. This is about the obsolete code testing module.

Does writing Rspec cases for an existing application make sense? Can we write a specification for an existing project

Yes. This is best when you write your tests before writing an application. It's never too late to write tests, starting late won't hurt. Testing Legacy Code: Adding Unit Tests to Legacy Code

Should we follow any recommendations for writing specifications for an already written application

My two cents on this:

  • Adding Tests Gradually

  • First check the most important parts of your application. Start by writing unit tests and focus on important models (instead of all models). After testing, your models will switch to functional tests (controllers) and integration tests. Remember: To eat an elephant, we need to eat one thing at a time.

  • If it is difficult for your existing models to write a test, this means that you need to reorganize your code. Refactoring to make your models easy to test.

  • Always write unit tests for new models / implementations from the time they run.

Useful links:

+8
source

It makes perfect sense to add test cases to existing code; this will help keep the application running as future improvements and bug fixes.

There is nothing about rspec that makes it different in particular; it's just a testing platform that allows you to test your code in many ways.

There is a lot of literature on writing tests for legacy code; combined with good documentation such as the “Rspec Book,” you should be able to get started.

+7
source

I wrote this gem https://rubygems.org/gems/autogen_rspec .

So, this gem has a function, but I feel that it requires some polishing.

How it works? Therefore, after we install this stone and start the server, the pearls will begin to register the whole rspec request, response and approval style. Therefore, if you set this to QA env, and since the QA team will check the regression, all URLs will be logged in the response file.

You can choose which test to select in order to save it in the test file.

0
source

All Articles