Re: [Boost-users] [Unit-Test] How to test private functions
From: Carlo Wood
Also, the above is slightly dangerous, as the 'public' would 'leak' beyond the #ifdef when TESTING is defined. You'd have to make sure that the test block at the end of the class.
This is a very good point. A method defined as public in test might fail to compile as private in production.
Personally, I like the #define private public best, because it doesn't polute the real code.
But this contradicts your prior good point. This is even more dangerous than the conditional public: which you objected to, because now *every* method is public! At least with the other method, you can do it safely if you're careful. - James Jones Administrative Data Mgmt. (v)732-510-1806 375 Raritan Center Pkwy, Suite A (f)732-510-1855 Edison, NJ 08837 Visit us on the web at http://www.firstinvestors.com/
On Fri, May 05, 2006 at 09:15:40AM -0400, james.jones@firstinvestors.com wrote:
From: Carlo Wood
Also, the above is slightly dangerous, as the 'public' would 'leak' beyond the #ifdef when TESTING is defined. You'd have to make sure that the test block at the end of the class.
This is a very good point. A method defined as public in test might fail to compile as private in production.
Personally, I like the #define private public best, because it doesn't polute the real code.
But this contradicts your prior good point. This is even more dangerous than the conditional public: which you objected to, because now *every* method is public! At least with the other method, you can do it safely if you're careful.
Personally, I don't think it is that much of a problem to define private
as public - but since the #ifdef solution was given in order to avoid
access to other private members, I felt to point out that it didn't do
a perfect job in that.
Nevertheless, I believe that the solution that I gave at the end of my
previous post has the best of both solutions. What did you think of that
solution? It is totally safe in that you will not accidently access
variables that should be private (or protected: the derived class is
very simple and straight forward, you won't make a mistake in that).
And on top of that, there is no need to add test code to the header
under test.
--
Carlo Wood
participants (2)
-
Carlo Wood
-
james.jonesīŧ firstinvestors.com