# Add\_assertion' called for nil:NilClass errror when testing

**URL:** <https://www.ruby-forum.com/t/add-assertion-called-for-nil-nilclass-errror-when-testing/177991>\
**Category:** Ruby\
**Created:** [October 27, 2009, 5:06pm UTC](https://www.ruby-forum.com/t/add-assertion-called-for-nil-nilclass-errror-when-testing/177991 "2009-10-27T17:06:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [October 27, 2009, 5:06pm UTC](https://www.ruby-forum.com/t/add-assertion-called-for-nil-nilclass-errror-when-testing/177991/1 "2009-10-27T17:06:32Z")

</div>

This @browser is defined in the login method  
@browser=Selenium::Client::Driver.new(“localhost”, 4444, “\*chrome”, $url  
, 10000);

class CrudDContent\<Test::Unit::TestCase  
def initialize()  
login(“browser\_name”)  
end#initialize()

def test\_createdc()  
assert(@browser.element?($x\_xpath))#the test fails at this assert  
end#test\_createdc()

end#CrudDContent\<Test::Unit::TestCase

When ever I run this program, I get the error :

C:/RubyInstall/ruby/lib/ruby/1.8/test/unit/testcase.rb:125:in  
`add_assertion': private method`add\_assertion’ called for nil:NilClass  
(NoMethodError)  
from C:/RubyInstall/ruby/lib/ruby/1.8/test/unit/assertions.rb:494:in  
`_wrap_assertion' from C:/RubyInstall/ruby/lib/ruby/1.8/test/unit/assertions.rb:61:in`assert’  
from ./content.rb:6:in `test\_createdc’  
from Driver.rb:8

Can someone take a look, I am out of ideas!

---

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [October 27, 2009, 6:12pm UTC](https://www.ruby-forum.com/t/add-assertion-called-for-nil-nilclass-errror-when-testing/177991/2 "2009-10-27T18:12:47Z")

</div>

Fixed, I needed to add the initalize the test methods after I called  
them

dc=CrudDContent.new()

def initialize(dc)  
super(dc)  
end #def initialize(dc)

dc.test\_createdc()

Arti S. wrote:

> This @browser is defined in the login method  
> @browser=Selenium::Client::Driver.new(“localhost”, 4444, “\*chrome”, $url  
> , 10000);
> 
> class CrudDContent\<Test::Unit::TestCase  
> def initialize()  
> login(“browser\_name”)  
> end#initialize()
> 
> def test\_createdc()  
> assert(@browser.element?($x\_xpath))#the test fails at this assert  
> end#test\_createdc()
> 
> end#CrudDContent\<Test::Unit::TestCase
> 
> When ever I run this program, I get the error :
> 
> C:/RubyInstall/ruby/lib/ruby/1.8/test/unit/testcase.rb:125:in  
> `add_assertion': private method`add\_assertion’ called for nil:NilClass  
> (NoMethodError)  
> from C:/RubyInstall/ruby/lib/ruby/1.8/test/unit/assertions.rb:494:in  
> `_wrap_assertion' from C:/RubyInstall/ruby/lib/ruby/1.8/test/unit/assertions.rb:61:in`assert’  
> from ./content.rb:6:in `test\_createdc’  
> from Driver.rb:8
> 
> Can someone take a look, I am out of ideas!
