Test::Unit::Omission - Unable to omit tests

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 methodomit’
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 methodexception_handler’ for Object:Class
(NoMethodError)
from test_omit.rb:5:in `include’
from test_omit.rb:5

Any suggestions to get this working?

-Champak

On Mar 3, 12:20 pm, Champak Ch [email protected] wrote:

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

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

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

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.

On Mar 5, 2010, at 09:18 , Champak Ch wrote:

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.

you can already selectively run tests via -n and -t. run your tests and
tack on --help for info.

On Mar 3, 2010, at 12:57, 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’

If you’re going to use the test-unit gem you must require files inside
it after gem ‘test-unit’

I simplified the code as much as possible below. omit is still not
recognised. Runs without any errors if omit() is removed. I am not sure
what I am really missing.

require ‘test/unit’

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

I get the following error when I run it as suggested above.

c:/ruby/lib/ruby/gems/1.8/gems/test-unit-2.0.6/lib/test/unit/autorunner.rb:120:in
expand_path': couldn't find HOME environment -- expanding~/.test-unit.xml’ (ArgumentError)
from
c:/ruby/lib/ruby/gems/1.8/gems/test-unit-2.0.6/lib/test/unit/autorunner.rb:120:in
initialize' from c:/ruby/lib/ruby/gems/1.8/gems/test-unit-2.0.6/lib/test/unit/autorunner.rb:49:innew’
from
c:/ruby/lib/ruby/gems/1.8/gems/test-unit-2.0.6/lib/test/unit/autorunner.rb:49:in
`run’
from
c:/ruby/lib/ruby/gems/1.8/gems/test-unit-2.0.6/lib/test/unit.rb:321

Any suggestions?

-Champak.

Hi,

In [email protected]
“Re: Test::Unit::Omission - Unable to omit tests” on Sat, 6 Mar 2010
11:58:25 +0900,
Champak Ch [email protected] wrote:

def test_02_omit
puts “\nHello 1”
omit()
puts “\nHello 2”
end

def test_03_logoff
puts “\nLogged off”
end
end

Please try the following code:


require ‘rubygems’
gem ‘test-unit’
require ‘test/unit’

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

Then run the file:

% ruby tc_my_tests.rb

Thanks,

Thanks for your reporting.
I’ve fixed it in trunk and release trunk as test-unit 2.0.7.
Please retry with test-unit 2.0.7 again.

Thank you for fixing this so quick. This worked without any errors when
I just ran the file.

Hi,

In [email protected]
“Re: Test::Unit::Omission - Unable to omit tests” on Tue, 9 Mar 2010
02:36:25 +0900,
Champak Ch [email protected] wrote:

new' from c:/ruby/lib/ruby/gems/1.8/gems/test-unit-2.0.6/lib/test/unit/autorunner.rb:49:in run’
from
c:/ruby/lib/ruby/gems/1.8/gems/test-unit-2.0.6/lib/test/unit.rb:321

Any suggestions?

Thanks for your reporting.
I’ve fixed it in trunk and release trunk as test-unit 2.0.7.
Please retry with test-unit 2.0.7 again.

Thanks,