1 / 6

Ruby Unit Test

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 )

mervyn
Download Presentation

Ruby Unit Test

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ruby Unit Test and other languages…

  2. 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.

  3. Create a class – failing test class Converter def feetToMeters (feet) return 1 end end

  4. 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

  5. Create a class – passing test class Converter @@FEET_TO_METERS = 0.3048 def feetToMeters (feet) return feet * @@FEET_TO_METERS; end end

  6. 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/

More Related