[ next ] [ prev ] [ contents ] [ skip to The First Story ] XP-Cinti TDD Workshop

Our First Test

We started with just an empty test framework.

# file: testnet.rb
require 'test/unit'

class TestNet < Test::Unit::TestCase
end

Ruby Comments: The require statement in Ruby looks in the ruby libraries for a file named 'test/unit.rb' and will load it in to the running program.

A class is introduced with the keyword class. Our test class inherits from a library class named Test::Unit::TestCase. The double colons act as namespace operators (similar to C++).

Time to run the test ...

  
$ ruby testnet.rb
Loaded suite testnet
Started...
.
Finished in 0.016573 seconds.
0 runs, 0 assertions, 0 failures, 0 errors

No surprise, but this shows that our test framework is working properly. (if you are following along with the tutorial, and your tests fail here, see note)

Let's add a real test now ...


[ next ] [ prev ] [ contents ] [ skip to The First Story ] Copyright 2003 by Jim Weirich.
Some Rights Reserved