From: Champak Ch on
I am trying to omit some tests while using the test unit framework. My
code and result below.

Code:
require 'rubygems'
gem 'test-unit'
require 'test/unit'

def testing
puts "hi1"
omit
puts "hi2"
end

testing

Error:
test_omit.rb:9:in `testing': undefined local variable or method `omit'
for main:Object (NameError)
from test_omit.rb:13
hi1
===========================================
I included the following lines in the code above

require 'test/unit/omission'
include Test::Unit::OmissionHandler

But I still get the error as below: -
c:/ruby/lib/ruby/gems/1.8/gems/test-unit-2.0.6/lib/test/unit/omission.rb:144:in
`included': undefined method `exception_handler' for Object:Class
(NoMethodError)
from test_omit.rb:5:in `include'
from test_omit.rb:5

Any suggestions to get this working?

-Champak
--
Posted via http://www.ruby-forum.com/.

From: Daniel Berger on


On Mar 3, 12:20 pm, Champak Ch <champ...(a)live.com> wrote:
> I am trying to omit some tests while using the test unit framework. My
> code and result below.
>
> Code:
> require 'rubygems'
> gem 'test-unit'
> require 'test/unit'
>
> def testing
>   puts "hi1"
>   omit
>   puts "hi2"
> end

Two things. First, your tests must be defined within a subclass of
Test::Unit::TestCase:

class MyTests < Test::Unit::TestCase
def test_omit
puts "hi1"
omit
puts "hi2"
end
end

Second, your tests should all start with "test_". Test-unit will
ignore all other methods, except for setup, teardown, self.startup and
self.shutdown.

Regards,

Dan

From: Champak Ch on
Thanks Dan. I have modified the code snippet I sent earlier to include
the details. I still get the same error.

require 'test/unit/testsuite'
require 'test/unit/ui/console/testrunner'
require 'rubygems'
gem 'test-unit'
require 'test/unit'
#require 'test/unit/omission'
#include Test::Unit::OmissionHandler

class TC_MyTests < Test::Unit::TestCase
def test_01_login
puts "\nLogged in"
end

def test_02_omit
puts "\nHello 1"
omit
puts "\nHello 2"
end

def test_03_logoff
puts "\nLogged off"
end
end

begin
suite = Test::Unit::TestSuite.new("My Test Cases")
suite << TC_MyTests.suite
end

-Champak
--
Posted via http://www.ruby-forum.com/.

From: Daniel Berger on
Champak Ch wrote:
> Thanks Dan. I have modified the code snippet I sent earlier to include
> the details. I still get the same error.
>
> require 'test/unit/testsuite'
> require 'test/unit/ui/console/testrunner'
> require 'rubygems'
> gem 'test-unit'
> require 'test/unit'
> #require 'test/unit/omission'
> #include Test::Unit::OmissionHandler

Get rid of the first 2 require lines. Also, you don't need to create a
suite. Just run the file.

Regards,

Dan

From: Champak Ch on
I was unable to get the omit functionality working, even after I removed
the first 2 require lines. The omit() function is not recognised at all.

However, in my application, I have a bunch of testsuites which I run
together. If I do not have omit, the script runs perfectly fine. But I
am trying to include the omit functionality, so I can selectively run my
tests within each test suite.

Please let me know if there are any examples that I could look at to get
this working.
--
Posted via http://www.ruby-forum.com/.