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

C

Champak Ch

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
 
D

Daniel Berger

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
=A0 puts "hi1"
=A0 omit
=A0 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
 
C

Champak Ch

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
 
D

Daniel Berger

Champak said:
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
 
C

Champak Ch

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.
 
E

Eric Hodel

Thanks Dan. I have modified the code snippet I sent earlier to include=20=
the details. I still get the same error.
=20
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'=
 
R

Ryan Davis

I was unable to get the omit functionality working, even after I = removed=20
the first 2 require lines. The omit() function is not recognised at = all.
=20
However, in my application, I have a bunch of testsuites which I run=20=
together. If I do not have omit, the script runs perfectly fine. But I=20=
am trying to include the omit functionality, so I can selectively run = my=20
tests within each test suite.

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

Champak Ch

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
 
K

Kouhei Sutou

Hi,

In <[email protected]>
"Re: Test::Unit::Omission - Unable to omit tests" on Sat, 6 Mar 2010 11:58:25 +0900,
Champak Ch said:
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

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,
 
C

Champak Ch

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:in
`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?

-Champak.
 
K

Kouhei Sutou

Hi,

In <[email protected]>
"Re: Test::Unit::Omission - Unable to omit tests" on Tue, 9 Mar 2010 02:36:25 +0900,
Champak Ch said:
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:in
`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,
 
C

Champak Ch

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top