简体   繁体   中英

Fail first unit test, if running through rake

I have Rakefile in my project.

mt_server_dir = File.expand_path('vendor/murder_traffic_server')

Rake::TestTask.new("test_vendor") do |t|
  chdir mt_server_dir
  t.libs = [mt_server_dir]
  t.test_files = Dir["#{mt_server_dir}/tests/test_*"]
  t.warning = true
end

When I run tests

rake test_vendor

First test in the list, always fail .

With error.

test_ip.rb:55: warning: instance variable @ip not initialized

That is mean, not execute setup method in first test.

When I run test directly.

ruby test_ip.rb

Test is successful.

I tried rename first test to test_zip.rb, and when I running test through rake, test is successful, but first in the list test test_dns.rb is failed.

Who know how fix it?

Thanks.

I checked out the source code of your app on Github.

Your test_ip.rb file defines class TestIp < Test::Unit::TestCase , as it should. However, your test_dns.rb file also defines class TestIp < Test::Unit::TestCase , whereas it should define class TestDns . Since that file also has def setup , that setup method overrides the test_ip one. This is why you see this error:

/home/dylan/dev/Murder-traffic/vendor/murder_traffic_server/tests/test_dns.rb:7: warning: method redefined; discarding old setup
/home/dylan/dev/Murder-traffic/vendor/murder_traffic_server/tests/test_ip.rb:7: warning: previous definition of setup was here

So, fix the class declaration in your test_dns.rb file and everything should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM