The problem is that you are calling your assertions within an instance of another class. If I recall correctly, assert increments the assertion count within its class instance. Therefore your assertion count is being incremented in your RubyDriver instance rather than the RubyTest instance. As a result, you get no assertions reported.
You need to do the assertions within the actual test case (ie test_method
of RubyTest) that is being run by test/unit.
As an example, you could make RubyDriver include your driving logic and logic for retrieving values to test. RubyTest would then call RubyDriver to setup/get values and include your test logic.
class RubyTest < Test::Unit::TestCase
def test_method
# Do some setup using RubyDriver instance
driver = RubyDriver.new("/home/pratik/study/UIAutomation/WatirScript.xlsx")
driver.call_driver
# Use RubyDriver to get some value you want to test
some_value_to_test = driver.get_value_to_test
# Do the assertion of the value within RubyTest
assert_equal(true, some_value_to_test, "Object does not exist")
end
end
An alternative solution might be to pass the test case (RubyTest) to RubyDriver. Then have RubyDriver call the assertion methods using the RubyTest instance.
Here is a simplified working example where you can see that your assertion count is correctly updated. Note that the RubyTest instance is passed to RubyDriver and stored in the @testcase variable. All assertions are then run with the context of the @testcase - eg @testcase.assert(false)
, which ensures that the original test cases' assertion counts are updated.
require 'test/unit'
class RubyDriver < Test::Unit::TestCase
def initialize(file, testcase)
@testcase = testcase
super(file)
end
def action
@testcase.assert(false)
end
end
class RubyTest < Test::Unit::TestCase
def test_method
driver = RubyDriver.new("/home/pratik/study/UIAutomation/WatirScript.xlsx", self)
driver.action
end
end
I left the RubyDriver as a sub-class of Test::Unit::TestCase, though it seems a bit odd unless you also have actual tests in the RubyDriver.