From: "Aleksi Niemelä" Date: 2000-08-11T17:29:05+02:00 Subject: [ruby-talk:04426] RE: Getting started with RubyUnit? I'd say the distributed package should contain all necessary instructions and pointers. I don't know if it's too much to ask, but as you learn things now, could you mark down all what you've found out and what's missing from the docs. That list could be the basis (or the complete solution) for the better docs. Particularly for RubyUnit I'd do this, but I've noticed that it works best when you don't know anything about the thing, as you don't have to pretend "asking stupid questions". At least, I don't have to :). Anyway, I know something about RubyUnit framework so it's not working for me anymore. Well, here's something to get you started. I assume you have installed RubyUnit. For each tested component (be it one file, one class, one method, the whole system...) I create one file test_foo.rb. The basic content in it is like this: require "runit/testcase" require "foo" class Test_Foo < RUNIT::TestCase # setup is called for each test, to provide, well, fresh setup :) def setup @foo_has = TheSetup.new("for each test, don't use if you don't need it") end # test's are like this, they have to start with "test_" # I continue with test number, to get them executed in some order def test_01_constructor # this test actually does not use what setup provides already foo = Foo.new assert_equal("foo", foo.foo) # expect foo.foo to return "foo" end def test_02_bar @foo.bar # uses what's setupped assert( @foo.bar == nil ) # assert call to the object bar returns # method == with parameter nil # returns something evaluating true end end if $0 == __FILE__ # here's my small driver to make this file runnable, thus self-standing test require 'runit/cui/testrunner' require 'runit/testsuite' runner = RUNIT::CUI::TestRunner.new # here you say what you want to test runner.run RUNIT::TestSuite.new(Test_Foo) end ################3 Look RubyUnit examples and assert.rb through to see what you can do and assert. Study these URLs a little. http://www.c2.com/cgi/wiki?UnitTests c2.com's pages at wiki at not bad to read completely! http://www.c2.com/cgi/wiki?TestingFramework Other implementations (and variations and examples). Notable Ruby is missing :(. http://www.xprogramming.com/software.htm Other implementations, notable Ruby is present. http://www.xprogramming.com/testfram.htm The Kent Beck's page explaining the framework. It's in smalltalk, so Ruby one was a little bit easier to me, but I'd say this is the authorative :). - Aleksi