Re: Should private/protected methods be included in test?

From: Date: Sat, 28 Mar 2009 13:29:21 +0000
Subject: Re: Should private/protected methods be included in test?
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-51684@lists.php.net to get a copy of this message
And how can you test private method if they cannot be called from outside the class? usually the unit test looks something like this: (I am testing Event_Dispatcher2 class here) function testOfgetNotificationName(){ $oEvent = Event_Dispatcher2::getInstance('custom', 'MyName'); $this->assertEqual('MyName', $oEvent->getNotificationName()); } But if the method is private, it's not possible to do this: $oEvent->_privateMethod(); It just will not work. Are there special tricks for testing private methods? On Sat, Mar 28, 2009 at 6:33 AM, David Jean Louis <izimobil@gmail.com>wrote: > Hello, > > Hello! >> Just wondering, what do you usually include in your test suite? >> >> Some websites recommend testing all public methods. This makes sense with >> exception of simple getters/setters methods. >> But what about the private/protected methods? Whould I also write test >> cases >> for those? >> > > Yes they should be tested, even more thoroughtly because private/protected > methods often handle the most critical parts of your logic ! > > >> By the way, is it OK to not write tests for simple getters/setters that >> only >> return or set an instance variable? >> >> > Yes, they should also be tested, if one day you change those > getters/setters to do more than setting a protected property, you'll be > happy to have them covered by tests. > > Anyway, you won't get a good code coverage if you skip code. > > -- > David >

« previous php.pear.dev (#51684) next »