Test Drive Development in Ruby On Rails

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Test Drive Development in Ruby On Rails - Presentation Transcript

      • Test Driven Development
      • By
      • Uma Mahesh Varma
    1. Test Drive Development
      • Introduction
      • Importance of T.T.D
      • Rails webs application directory structure
      • Explanation about test folder in rails directory structure
      • Unit Tests
      • Functional Tests
    2. What is meant by test drive development ? 
      • The answer for the above question is as fallows, TTD (Test Drive Development) is an part of software development techniques based on writing some small test cases before implementing code or new functionalities. 
      • Test drive development is nothing but developing a product by writing unit tests that define the code requirement. These tests returns true or false. Running these tests rapidly brings you a correct behavior of the developer to develop an application. 
    3. Procedure of T.D.D
      • Write a test. 
      • Run the test and check whether it fails or not.
      • If not Write some code.
      • Run the automated test.
      • Refactor.
    4. Rails webs application directory structure
      • my_app/
      • README Installation and usage information
      • Rakefile Build script
      • app/ Model, View, and Controller files go here
      • components/ Reusable components
      • config/ Configuration and database connection parameters
      • db/ Schema and migration information
      • doc/ Autogenerated documentation
      • lib/ Shared code
      • log/ Logfiles produced by your application
      • public/ Web-accessible directory. Your application runs from here
      • script/ Utility scripts
      • test/ Unit, functional, and integration tests, fixtures, and mocks
      • tmp/ Runtime temporary files
      • vendor/ Imported code
    5. Test directory
      • Fixtures
      • Integration
      • Functional
      • Unit
      • test_helper.rb
    6. Unit Test
      • require File.dirname(__FILE__) + '/../test_helper‘
      • class UserTest < Test::Unit::TestCase
      • fixtures :users
      • def test_truth
      • assert true
      • end
      • end
    7. Unit Test
      • >> ruby test/unit/test_user.rb
      • Loaded suite test/unit/user_test
      • Started
      • EE
      • Finished in 0.559942 seconds.
      • 1) Error:
      • test_truth(UserTest):
      • MysqlError: Unknown database ‘myapp_test'
      • 1 tests, 0 assertions, 0 failures, 2 errors
    8. Unit Test
      • A Database Just for Tests
      • Myapp> mysqladmin -u root create myapp_test
      • Myapp> ruby test/unit/myapp_test.rb
      • Loaded suite test/unit/myapp_test
      • Started
      • E
      • Finished in 0.06429 seconds.
      • 1) Error:
      • test_truth(ProductTest):
      • ActiveRecord::StatementInvalid: MysqlError:
      • Table ‘myapp_test. users' doesn't exist: DELETE FROM users
      • 1 tests, 0 assertions, 0 failures, 1 errors
    9. Unit Test
      • myapp > rake db:test:prepare
      • Myapp > ruby test/unit/user_test.rb
      • Loaded suite test/unit/user_test
      • Started
      • .
      • Finished in 0.085795 seconds.
      • 1 tests, 1 assertions, 0 failures, 0 errors
    10. Unit Test
      • A Real Unit Test
      • validates_presence_of :name, :email, :mobilenum
      • validates_numericality_of : mobilenum
      • validates_uniqueness_of :name
      • validates_format_of :image_url,
      • :with => %r{.(gif|jpg|png)$}i,
      • :message => &quot;must be a URL for a GIF, JPG, or PNG image&quot;
    11. Unit Test
      • def test_invalid_with_empty_attributes
      • user = User.new
      • assert ! user .valid?
      • assert user .errors.invalid?(:name)
      • assert user .errors.invalid?(:email)
      • assert user .errors.invalid?(:mobileno)
      • assert user.errors.invalid?(:image_url)
      • end
    12. Unit Test
      • Myapp > ruby test/unit/user_test.rb
      • Loaded suite test/unit/user_test
      • Started
      • ..
      • Finished in 0.092314 seconds.
      • 2 tests, 6 assertions, 0 failures, 0 errors
    13. Unit Test
      • def test_image_url
      • ok = %w{ fred.gif fred.jpg fred.png FRED.JPG FRED.Jpg
      • http://a.b.c/x/y/z/fred.gif }
      • bad = %w{ fred.doc fred.gif/more fred.gif.more }
        • ok.each do |name|
          • user = User.new(:name => “mahesh&quot; ,
          • :email => “umamahesh_nyros@yahoo.com&quot; ,
          • :mobilenum => 9866439593,
          • :image_url => name)
          • assert user.valid?, usererrors.full_messages
        • end
        • bad.each do |name|
          • user = User.new(:name => “mahesh&quot; ,
          • :email => “umamahesh_nyros@yahoo.com&quot; ,
          • :mobilenum => 9866439593,
          • :image_url => name)
          • assert user.valid?, usererrors.full_messages
        • end
    14. Fixtures
      • mahesh:
      • id: 1
      • name: mahesh
      • email: [email_address]
      • mobilenum: 9866439593
      • image_url: maheshprofile.jpg
    15. Unit Test
      • Fixtures :users
      • def test_unique_name
      • user = User.new(:name => user(:mahesh).name,
      • :email => “umamahesh_nyros@yahoo.com&quot; ,
      • :mobilenum => 9866439593,
      • :image_url => &quot;fred.gif&quot; )
      • assert !user.save
      • assert_equal &quot;has already been taken&quot; , user.errors.on(:name)
      • end
    16. Unit test supports
      • assert(boolean,message)
      • assert_equal(expected, actual,message)
      • assert_not_equal(expected, actual,message)
      • assert_nil(object,message)
      • assert_not_nil(object,message)
      • assert_match(pattern, string,message)
      • assert_no_match(pattern, string,message)
    17. Functional Testing of Controllers
      • require ‘user_helper’
      • def UserTest < Test::Unit::Testclass
      • def test_index
      • assert true
      • end
      • end
    18. Functional Testing of Controllers
      • myapp > ruby test/functional/user_test_controller.rb
      • Loaded suite test/functional/ user_test_controller.rb
      • Started
      • .
      • Finished in 0.0604571 seconds.
      • 1 tests, 1 assertions, 0 failures, 0 errors
      • Thank You

    + Nyros TechnologiesNyros Technologies, 6 months ago

    custom

    538 views, 0 favs, 1 embeds more stats

    Seminar presentation on Test Drive Development in R more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 538
      • 531 on SlideShare
      • 7 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 6
    Most viewed embeds
    • 7 views on http://www.developers-blog.com

    more

    All embeds
    • 7 views on http://www.developers-blog.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories