From: Farrel Lifson Date: 2006-11-30T23:12:23+09:00 Subject: Re: Test::Unit and drb On 30/11/06, Damphyr wrote: > Anybody have any tips to share about unit testing code that uses drb? > > My problem is, I can test all the the logic in smaller chunks, but as > soon as I integrate everyhting and have code in place that verifies and > recovers from connection errors I need to at least establish that drb > connection. > > How would I go about doing this in a unit test environment? > Getting a mock drb server in a thread and launching it in setup seems > too clunky. > Any brilliant ideas? > Cheers, > V.- > -- > http://www.braveworld.net/riva > > This is how I've done it though if anyone has better solutions I'd be glad to hear them: require 'drb' require 'test/unit' class Counter def initialize;@counter = 0;end def count;@counter+=1;end def self.start DRb.start_service("druby://localhost:9000",self.new) end def stop DRb.stop_service end end class TC_Counter < Test::Unit::TestCase def setup @t = Thread.new do Counter.start end @counter = DRbObject.new_with_uri("druby://localhost:9000") end def teardown @counter.stop @t.exit end def test_count assert_equal(1,@counter.count) assert_equal(2,@counter.count) assert_equal(3,@counter.count) end end