Export (0) Print
Expand All

How to: Regenerate Private Accessors

Visual Studio 2005

When you generate a unit test for a private method, a private accessor is automatically created. A private accessor is a method that the test method uses to access the private code.

When you change a private method in your code-under-test file, you might have to regenerate the test's private accessors, as described in the following procedure.

NoteNote

After you regenerate private accessors, subsequent runs of the unit test for private methods might fail; in particular, you might see compile-time failures in your test project. This occurs because, although the private accessors are now up to date, unit test methods are still dependent on the previous definitions of the private accessors and must now be updated. To fix this error, regenerate the unit test; see How to: Generate a Unit Test. The new unit test, which will now correctly reference the newly regenerated private accessor, is appended to the end of the test source-code file. If you have worked in the original unit test, such as by assigning values in lines that contain // TODO: comments, you will want to copy the code you changed from the original unit test into the new version of the test.

To regenerate private accessors

  1. Open the source-code file that contains the private method that has changed.

  2. Right-click in this source-code file, point to Create Private Accessor, and select the test project into which to place the updated private accessors file.

    To the VSCodeGenAccessors file, this adds a new accessor class that contains methods for retrieving values of the entities in the private class being tested.

    NoteNote

    Do not edit the VSCodeGenAccessors file by hand.

    This creates up-to-date private accessors for all the private methods in your code-under-test file, whether private accessors for them existed previously.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft