Introduction to Rails' Unit Testing

3,262 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,262
On SlideShare
0
From Embeds
0
Number of Embeds
62
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Introduction to Rails' Unit Testing

  1. 1. Hello(Mic).Testing (1,2,3) { :by => { :name =>“ Manik Juneja ”, :company => “ vinsol ” } }
  2. 2. Warning <ul><li>This presentation is not about standards. </li></ul><ul><li>So let’s restore the sanity and look at some code here. </li></ul>
  3. 3. Testing <ul><li>Testing, one of the most important, yet most looked down upon component of software development </li></ul><ul><li>Most of us as developers, do certain amount of testing. </li></ul><ul><li>The question is how much of that is automated. </li></ul><ul><li>So that when we make a change here we are sure that we did not break something there. </li></ul>
  4. 4. Testing and Rails <ul><li>The Rails framework has inbuilt support for three levels of testing </li></ul><ul><li>Unit Testing of Models </li></ul><ul><li>Functional Testing of Controllers </li></ul><ul><li>Integration Testing of Applications </li></ul>
  5. 5. Fixtures <ul><li>Fixtures allow us to specify a set of known data to be available in the table, at the start of every unit test. </li></ul><ul><li>Fixtures are transactional </li></ul><ul><li>Fixtures are instantiated, allowing us to access them within the test cases. </li></ul>
  6. 6. assertions <ul><li>These are the most frequently used assertions. </li></ul><ul><li>assert(boolean, message) </li></ul><ul><li>assert_equal(expected, actual, message) </li></ul><ul><li>assert_not_equal(expected, actual, message) </li></ul><ul><li>assert_nil(object, message) </li></ul><ul><li>assert_not_nil(object, message) </li></ul><ul><li>There are a lot more, and it is easy to write your own customer assertions too. </li></ul>
  7. 7. rake <ul><li>To run all unit test cases for an application </li></ul><ul><li>$ rake test:units </li></ul>
  8. 8. When to write unit tests. <ul><li>From Agile Developer Venkat’s blog post titled </li></ul><ul><li>“ Walking along the development beach” </li></ul><ul><li>http://www.agiledeveloper.com </li></ul><ul><li>… ....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. ….. </li></ul>

×