Unit Testing Ruby on Netbeans IDE
For ruby unit testing, we need to extend from the class "Test::Unit:: TestCase? ". Suppose the following "Demo" class exists. It has only one method ie “return_two”. class Demo def return_two 2 end end The method "return_two" returns the value 2. We could have written "return 2" or just "2" since ruby returns the value of the last line in the method. Now let us write the class to test the "Demo" class. I have used Netbeans IDE. By convention, we have to name test classes as "Test+ ClassName? ". So we have " TestDemo? " as the classname. Here is the ruby code. $:.unshift File.join(File.dirname(__FILE__),'..','lib') require 'test/unit' require 'demo' class TestDemo < Test::Unit::TestCase def test_foo d= Demo.new assert_equal 2, d. return_two # assert_equal("foo", bar) end def test_fail d= Demo.new assert_equal 3, d. re...