Test Drive Development in Ruby On Rails

  • 2,278 views
Uploaded on

Seminar presentation on Test Drive Development in Ruby on Rails by Uma Mahesh Varma at Nyros Technologies, kakinada, India

Seminar presentation on Test Drive Development in Ruby on Rails by Uma Mahesh Varma at Nyros Technologies, kakinada, India

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,278
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
23
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1.
    • Test Driven Development
    • By
    • Uma Mahesh Varma
  • 2. 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
  • 3. 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. 
  • 4. 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.
  • 5. 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
  • 6. Test directory
    • Fixtures
    • Integration
    • Functional
    • Unit
    • test_helper.rb
  • 7. Unit Test
    • require File.dirname(__FILE__) + '/../test_helper‘
    • class UserTest < Test::Unit::TestCase
    • fixtures :users
    • def test_truth
    • assert true
    • end
    • end
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. 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;
  • 12. 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
  • 13. 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
  • 14. 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
  • 15. Fixtures
    • mahesh:
    • id: 1
    • name: mahesh
    • email: [email_address]
    • mobilenum: 9866439593
    • image_url: maheshprofile.jpg
  • 16. 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
  • 17. 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)
  • 18. Functional Testing of Controllers
    • require ‘user_helper’
    • def UserTest < Test::Unit::Testclass
    • def test_index
    • assert true
    • end
    • end
  • 19. 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
  • 20.
    • Thank You