开发者

MS Test - Access Private Property

I have a Private property that I want to access in my MS Test unit test.

    // Make a local property for control so that we can mock the control object.
    private Control localControl
    {
        get{return Control.Instance;}
    }

I go to that unit, right click and select Create Private Accessor->MyUnitTestProject

The status bar says that the accessor was made for the project (no the unit).

开发者_JS百科But when I try to call it (mediator.localControl) it cannot find it.


Usually it builds a wrapper object named: <YourClassName>_Accessor that you use to access private properties and methods.

So if Control is the object that you are wanting to see the private property on there should be an object called Control_Accessor that you can create that will expose the private properties...

Edit: The easiest way I find to make sure that I can access a private property or method is to right click it from your class and then click create unit test. You then can see how it's done and then modify your test method to suit your needs.


You need to compile the test project before you will get intellisense support for the private accessor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜