tag:blogger.com,1999:blog-9620948.post3747320638472093561..comments2023-10-20T12:24:17.734-07:00Comments on Binstock on Software: Unit Testing Private Variables and FunctionsAndrew Binstockhttp://www.blogger.com/profile/16321156191558412680noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-9620948.post-4298503018417006922011-03-21T07:53:50.574-07:002011-03-21T07:53:50.574-07:00Im trying to solve this issue right now as well. I...Im trying to solve this issue right now as well. In C++, i could either use a friend class, make the test class inherit from the class im trying to test(private functions are still inacessable).Neil Sikkahttps://www.blogger.com/profile/09709856046012286983noreply@blogger.comtag:blogger.com,1999:blog-9620948.post-85667563907841003382009-06-20T22:18:53.084-07:002009-06-20T22:18:53.084-07:00I found this post when searching for the same answ...I found this post when searching for the same answer.. I have used an accessor before. This allows you to make an accessor object of the class you want to test in your test class. This object has access to the private variables and methods in your class. I have unfortunatly gorgot exactly how to create the accessor object, hence the googling.. =)Anonymoushttps://www.blogger.com/profile/17489175715099700632noreply@blogger.comtag:blogger.com,1999:blog-9620948.post-12085115751158337882007-12-13T07:45:00.000-08:002007-12-13T07:45:00.000-08:00Two very good tools for this purpose is Test Subcl...Two very good tools for this purpose is Test Subclasses and moving the previously private part into a method object or strategy. <BR/><BR/>The later gives you two benefits, firstly you get very localized tests for that part making it easy to spot trouble areas, and it gives you a good test hook for free to use when testing the containing class's interactions with the strategy via mocks or other test doubles.<BR/><BR/>Both incurrs a bit of design overhead but for non trivial cases I've found it to often be worth the effort.Torbjörn Gyllebringhttps://www.blogger.com/profile/12440238354205811138noreply@blogger.comtag:blogger.com,1999:blog-9620948.post-26660458653790911842007-05-18T02:18:00.000-07:002007-05-18T02:18:00.000-07:00Corey: Thanks for the note and the link. I've neve...Corey: Thanks for the note and the link. I've never used reflection for this purpose. I like it but, as you state, it's not as clean as designing the code better--a task that continues to resist my best efforts ;-)Andrew Binstockhttps://www.blogger.com/profile/16321156191558412680noreply@blogger.comtag:blogger.com,1999:blog-9620948.post-69448776881500963632007-05-17T14:50:00.000-07:002007-05-17T14:50:00.000-07:00I've seen as much done using reflection before. (...I've seen as much done using reflection before. (http://en.wikibooks.org/wiki/Java_Programming/Reflection/Accessing_Private_Features_with_Reflection has some good example code.) I think Jeff is pretty right on, however, that you're in better shape if you can refactor to the point where you don't need testing kluges like reflection.Unknownhttps://www.blogger.com/profile/16527714113603642616noreply@blogger.com