[ next ] [ prev ] [ contents ] Using Ruby

Unit Testing

#!/usr/bin/env ruby

require 'test/unit'
require 'trio'

class TestTrio < Test::Unit::TestCase
  def setup
    @trio = Trio.new(1,2,3)
  end

  def test_trio
    assert_equal [1,2,3], @trio.to_a
  end
end

Output

Loaded suite src/testtrio
Started
.
Finished in 0.000729 seconds.

1 tests, 1 assertions, 0 failures, 0 errors

  • The Test::Unit framework comes with Ruby

  • The test class inherits from Test::Unit::TestCase

  • Test methods must be named "test_xxx"

  • Invoke as
    • ruby testfile.rb


[ next ] [ prev ] [ contents ] Copyright 2003 by Jim Weirich.
Some Rights Reserved