[TYPO3-dev] Unit tests and method visibility
    Bastian Waidelich 
    bastian at typo3.org
       
    Thu Jul  9 17:35:37 CEST 2009
    
    
  
Francois Suter wrote:
Hi Francois,
> I have read in the meantime that protected and private method should not 
> normally be tested as they represent inner workings of the class.
That is somewhat true because refactoring will become very costly if you 
test too much of the inner workings (as you'd have to adopt lots of test 
cases).
You don't want to test _how_ a class works internally, but you want to 
make sure it's API behaves as expected.
The problem: With TYPO3 and other frameworks protected methods are 
_part_ of the API in most cases and you want to test them too.
Luckily Robert has created a really adjuvant helper and Jochen 
backported it to Extbase: buildAccessibleProxy().
See 
https://svn.typo3.org/TYPO3v4/CoreProjects/MVC/extbase/trunk/Tests/Base_testcase.php
It allows you to create a proxy object for your class enabling you to 
call protected (not private) methods and to set/get protected properties.
Good luck and happy testing
Bastian
    
    
More information about the TYPO3-dev
mailing list