A novice programmer to write test procedures for the old code


I insist on going to the gym to do exercise and lifting weights. I like the feeling that I am stronger and healthier. About two months ago, my knees began to feel pain, but I was still strong enough to exercise.

I want to make myself stronger, completely ignore the health problems of the legs, still forced to continue their weightlifting. As you can imagine, the pain in my knee has not improved, and I will need a longer recovery every time I get exhausted.

as a junior programmer in Rackspace company (Airbrake Development Group), I often have a similar feeling, a large number of output code it urged me to stop, think that this can make the product more strong. Just as my knees have to suffer every time they squat, the old features of the test start to break down under the weight of a large number of new features.

My therapist

finally convinced me that I should focus on rehabilitation exercises, the restoration of the former do not go to weightlifting. He said that when the knee problem is good, the muscles become stronger and stronger, I will progress more quickly, it is not easy to hurt themselves, so that their pain.

remembered the advice, and I saw the link between it and work. I forced myself to write the old code, the old function to test the code, which makes my development faster, more confidence in the code, no longer worried about the development of new code will destroy the old code function.

here are some of the key points I learned during this transition:

development tools are very important

I use RSpec, Capybara, FactoryGirl and Selenium to test my Rails application. Before you write the test code, you have to look at these tools. Otherwise, it will waste a lot of time to debug the code.

some simple tasks, such as cleaning the database before and after testing, are important to ensure that you are able to do the right, fast, repeatable tests. For these tasks, you can use this database_cleaner gem.

if you are the first person in the team to write test code, this time the choice of test tools is particularly important, it will affect the other team members to accept the test. The entire team will submit the test program, so you have to make the process as simple as possible, using powerful, flexible tools.

existing code just to tell you what is now done, but not to tell you the code should actually be the case.

when I started testing other people’s code, I found a habit, first assume that the code is correct, and meet the requirements, so the code can pass the test case. Sometimes it’s okay