ruby unit test n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Ruby Unit Test PowerPoint Presentation
Download Presentation
Ruby Unit Test

Loading in 2 Seconds...

play fullscreen
1 / 6

Ruby Unit Test - PowerPoint PPT Presentation


  • 117 Views
  • Uploaded on

Ruby Unit Test. and other languages… . Process. Create your class with failing methods Create a test class Must extend Test::Unit:: TestCase Must require 'test/unit' Create one or more test methods Name must start with test (e.g., test_conversion )

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Ruby Unit Test' - mervyn


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
ruby unit test

Ruby Unit Test

and other languages…

process
Process
  • Create your class with failing methods
  • Create a test class
    • Must extend Test::Unit::TestCase
    • Must require 'test/unit'
  • Create one or more test methods
    • Name must start with test (e.g., test_conversion)
  • If separate file, must require the class being tested
    • require_relative “Converter”
    • require “./Converter”
  • Run the test program from the command line. All methods beginning with “test” will be executed.
create a class failing test
Create a class – failing test

class Converter

def feetToMeters (feet)

return 1

end

end

unit test
Unit Test

can use assert_equal for int

require 'test/unit'

class ConverterTest< Test::Unit::TestCase

@@EPSILON = 0.0001

def test_feetToMeters

converter = Converter.new

assert_in_delta(3.048,

converter.feetToMeters(10), @@EPSILON)

assert_in_delta(0.3048,

converter.feetToMeters(1), @@EPSILON)

assert_in_delta(0.4572,

converter.feetToMeters(1.5), @@EPSILON)

end

end

create a class passing test
Create a class – passing test

class Converter

@@FEET_TO_METERS = 0.3048

def feetToMeters (feet)

return feet * @@FEET_TO_METERS;

end

end

resources
Resources

http://apidock.com/ruby/Test/Unit/Assertions/assert_in_delta

http://apidock.com/ruby/Test/Unit/Assertions/assert_equal

http://www.ruby-doc.org/stdlib-2.0/libdoc/test/unit/rdoc/

There are several Behavior-Driven tools

http://rspec.info/

http://expectations.rubyforge.org/