Code and Development

Test Driven Development Will Save Your Project

Hey! It’s Weijie, and it has been about a month since the beginning of my first full time Ruby Developer position. My first month has been full of new experiences. I have learned that working on a development team is entirely different than programming on my own and also that the coding is on a whole different level of complication when working with a full blown commercial website. The most important thing that I have learned through this experience is that Test Driven Development is key to an error-free website.

Test Driven Development works on the concept of writing tests before writing code for the website. This seemed like a very foreign concept to me at first because it seemed like extra unnecessary work but now I understand the importance of having functional tests.  An example of TDD can be seen in the following lines of code:

Purpose: *Print out “Hello World” *

TDD: spec_file

describe “when I go to the root page of my website” do

it “prints out Hello World” do

assert_content(“Hello World”)

end

end

Actual Code: puts “Hello World”

To explain what is going on in my test, I’ll start by saying that the strings in the describe and it blocks are used to give scope to the test. It is descriptive and easily readable. The assert_content is the portion that actually makes sure that “Hello World” is printed to the web page. This practice is extremely useful when your codes become longer and longer. Your tests will make sure that each portion of your website stays working the way its supposed to be as you add more features and complications.

I hope you give TDD a try because it will make a huge improvement on your coding skills!

-Weijie

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s