Unit Testing Venkat Subramaniam – svenkat@cs.uh.edu 1 Unit Testing • Venkat’s rant on Unit Testing – What is it? – Benefits – Ruby’s emphasis on it Venkat Subramaniam – svenkat@cs.uh.edu 2
Your Test • Your Test inherits from Test: : Unit: : TestCase – require ‘test/ unit’ • Use assert methods like assert_equals • Test methods start with test prefix • setup and teardown methods Venkat Subramaniam – svenkat@cs.uh.edu 3 Running Tests • ruby testfilename.rb • ruby testfilename.rb –name test_name Venkat Subramaniam – svenkat@cs.uh.edu 4
Asserts • assert • assert_nil • assert_not_nil • assert_equal • assert_not_equal • assert_in_delta • assert_raise • assert_nothing_raised • assert_instance_of • assert_kind_of • assert_respond_to • assert_match • assert_no_match • assert_same • assert_not_same • assert_operator • assert_throws • assert_send • flunk Venkat Subramaniam – svenkat@cs.uh.edu 5 Unit Tests Venkat Subramaniam – svenkat@cs.uh.edu 6
Organizing Your Tests • Put your tests in a test directory parallel to the code directory • To run your tests from different directories you need to help ruby located it • The above modified $: (variable that represents load path) so that it gets the ../ src directory relative to where the test is Venkat Subramaniam – svenkat@cs.uh.edu 7 The $: magic Venkat Subramaniam – svenkat@cs.uh.edu 8
Organizaing your tests Venkat Subramaniam – svenkat@cs.uh.edu 9
Recommend
More recommend