So let’s restore the sanity and look at some code here.
Testing
Testing, one of the most important, yet most looked down upon component of software development
Most of us as developers, do certain amount of testing.
The question is how much of that is automated.
So that when we make a change here we are sure that we did not break something there.
Testing and Rails
The Rails framework has inbuilt support for three levels of testing
Unit Testing of Models
Functional Testing of Controllers
Integration Testing of Applications
Fixtures
Fixtures allow us to specify a set of known data to be available in the table, at the start of every unit test.
Fixtures are transactional
Fixtures are instantiated, allowing us to access them within the test cases.
assertions
These are the most frequently used assertions.
assert(boolean, message)
assert_equal(expected, actual, message)
assert_not_equal(expected, actual, message)
assert_nil(object, message)
assert_not_nil(object, message)
There are a lot more, and it is easy to write your own customer assertions too.
rake
To run all unit test cases for an application
$ rake test:units
When to write unit tests.
From Agile Developer Venkat’s blog post titled
“ Walking along the development beach”
http://www.agiledeveloper.com
… ....Think of your code as your left foot. Think of your unit test as your right foot. It really does not matter which foot you put forward first. However, when taking a nice walk on the beach, you wouldn’t let one foot take a mile walk before dragging the other foot to catch up. To keep your balance and make the walk pleasant, you follow a rhythm, placing one foot forward and following it with the other foot within safe and comfortable distance. …..
0 comments
Post a comment