On Tue, Feb 18, 2003 at 06:54:08AM +0900, Daniel Carrera wrote: > Here is a simple case. Say I write a private method to add two numbers: Testing of private methods was discussed in the last week or so; this list is hard to keep up with :-) You have to use 'send' to bypass the private restriction. > class MyClass > private > def add(a,b) > return a+b > end > end > > And I want to - say - assert that the return value is larger than the > first input value. How can I use Test::Unit to make this assertion? require 'test/unit' require 'myclass' class MyTest < Test::Unit::TestCase def setup @foo = MyClass.new end def test_add result = @foo.send(:add,5,3) assert(result==8, "Oops! I can't add!") end end Of course you'd probably loop over different sets of operands for a more comprehensive test (store the operands and the expected results in a constant array, for example) > How can I use Test::Unit to assert in-between steps inside my methods? I don't think you can; you treat your methods as black boxes, put data in, and see if you get the right data out. > Currently I have things like: > > condition or raise "condition was not met" > > How can I replace this sort of thing by test units? If your method raises exceptions, then they will be caught by the test harness: try adding raise "bomb!" if a == 5 to the 'add' method above. If these exceptions are just defensive programming, then you shouldn't need to do any more, since you don't expect them to be triggered. If you want your unit tester to check that an exception *is* actually raised under specific conditions, then use a begin..rescue..else..end construct in the test, and pass in data which causes those conditions. Regards, Brian.