Farinha
Farinha

Reputation: 18091

Private Accessor for method is not found

I'm getting this error when generating a new unit test under Visual Studio 2010 using the context menu (right-click the method name -> "Generate Unit Tests"):

Private Accessor for methodName is not found. Please rebuild the containing project or run the Publicize.exe manually.

The method is public (checked that by applying applying a filter to not show non-public methods in the "Generate Unit Tests" dialog.

Visual Studio creates some kind of .accessor file automatically. Do I need to do anything in it?

What else could be the problem?

EDIT (more info that might be relevant)

Upvotes: 7

Views: 12961

Answers (2)

rwoodford
rwoodford

Reputation: 135

I resolved my problem with this, I had disassociated the Test Reference folder during a botched merge with TFS.

The Test Reference folder lives in your test project and will contain a file named after the source namespace with ".accessor" appended to it. Since I had dissociated the folder from my project I didn't see that the file was still there, so I highlighted the test project and pressed the "Show All Files" button in Solution Explorer. When I finally found the file, I deleted it and re-generated the private accessor (right click in your class and choose "Generate Private Accessor").

So bottom line, if Test Reference exists but is disassociated from the Project you won't be able to regenerate the private accessor and Visual Studio will not tell you that there is a file naming/locking conflict.

Upvotes: 5

Vivian River
Vivian River

Reputation: 32390

The "accessor" is a class that works like one of the classes involved in your test, but the test method has access to its private and protected methods and fields. In particular, accessor classes are used for testing private and protected methods.

It sounds like there is a problem with the accessor, so you might want to try erasing and re-creating it. Rebuild the project. Then, right mouse click on your code and near where it says "Create Unit Tests", there should be another option that says "Create Private Accessor".

Upvotes: 0

Related Questions