I suggest you ...

Bring Back Private Accessor

Deprecated with VS 2012, I think the work suggestions around are not really handy (see http://msdn.microsoft.com/en-us/library/hh507838.aspx).

Using PrivateObject is not really productive. In case you need to rename a method, you have to do a String.Replace. Not type safe, no IntelliSense support.

To create a reflection framework by myself does not seem to be a valid option. Who has the time to build up the required knowledge and support the framework?

Declaring the code needed by the test as internal and use InternalsVisibleToAttribute means to soften my initial intention on who should be able to access the code. When I declare code as private, it means the no other class should be able to access it, even it is part of the same assembly.

I know, there are discussions why I should access private methods in unit tests at all. I do not share that point of view. Unit testing is white box testing to me. Having complex private business logic orchestrated by one public method, I want to test all the parts themselves. Including setting up error scenarios / states that I would never be able to create when I only access the public interface. From my point of view, this keeps the tests themselves much more maintainable (small and simple). Unit testing is not just positive, but also negative testing (error and exception handling).

Building high quality software in a productive manner requires the private accessor. As said by the VS 2005 doc about testing a private method: "… this task is more difficult for private than for public methods because it requires a deeper understanding of the intricacies of reflection. You will therefore find it advantageous to generate tests for private methods instead of coding them by hand."

84 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Stefan shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    Thanks for taking the time to share this suggestion. This item has been around for a couple of versions of Visual Studio and we haven’t acted on it. Looking at the VS “15” plans, we’re not going to take action on this item, so we’re going to close it. If the suggestion is still relevant, please either take a look to see if there’s another suggestion that’s similar that you can vote on, or open a new suggestion.

    - The Visual Studio Team

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • A. Aajajj commented  ·   ·  Flag as inappropriate

        Agreed! The C++ standard was written with existing code in mind, so even though it made sense to standardize the sizes of data types, it was omitted in order to maintain compatibility with all the legacy code out there in the wild. Bring back private accessors so we can continue doing our jobs instead of playing catch-up with your new tools!

      Feedback and Knowledge Base