我在使用我的测试类中定义的全局变量时遇到问题,然后在库文件中引用了该变量。我正在使用 Ruby 1.9.3p392 和测试单元 2.5.4。
这是运行测试的代码:
require 'rubygems'
gem 'test-unit'
require 'test/unit'
require 'ci/reporter/rake/test_unit_loader'
load '../lib/functions.rb'
require 'watir'
class Test_002 < Test::Unit::TestCase
include Functions
class << self
def startup
@browser = Watir::Browser.new :ie
@browser.speed = :fast
end
def shutdown
@browser.close
end
end
def test_001_login
login('some_url', 'some_user', 'some_passw')
end
end
这是包含登录功能的库的一部分:
require 'rubygems'
module Functions
def login(url, user, passw)
@browser.goto(url)
...
end
end
这是输出:
Started
E
===============================================================================
Error: test_001_login(Test_002)
NoMethodError: undefined method `goto' for nil:NilClass
(...)
23: end
24:
25: def test_001_login
=> 26: login('some_url', 'some_user', 'some_passw')
27: end
28:
29: end
===============================================================================
Finished in 3.0043 seconds.
1 tests, 0 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
0% passed
0.33 tests/s, 0.00 assertions/s
有任何想法吗?