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
on 2010-03-03 20:20
on 2010-03-03 21:25
On Mar 3, 12:20 pm, Champak Ch <champ...@live.com> 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
on 2010-03-03 21:57
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
on 2010-03-05 12:53
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
on 2010-03-05 18:18
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 2010-03-05 19:40
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'
on 2010-03-05 23:30
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 2010-03-06 03:58
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
on 2010-03-06 04:14
Hi, In <9fe46c8b5818159d02e1d95a71ba5e25@ruby-forum.com> "Re: Test::Unit::Omission - Unable to omit tests" on Sat, 6 Mar 2010 11:58:25 +0900, Champak Ch <champaka@live.com> 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,
on 2010-03-08 18:36
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.
on 2010-03-09 13:11
Hi, In <229c73c47bcc228c3edf225a5c5e617a@ruby-forum.com> "Re: Test::Unit::Omission - Unable to omit tests" on Tue, 9 Mar 2010 02:36:25 +0900, Champak Ch <champaka@live.com> 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,
on 2010-03-10 00:11
> 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.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.