VS 在生成单元测试时使用的 Shadowing 属性是什么? [英] What is the Shadowing attribute that the VS uses when it generates unit tests?

查看:38
本文介绍了VS 在生成单元测试时使用的 Shadowing 属性是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我生成单元测试时,Visual Studio 添加了一些模拟我的类的虚构类并添加了Shadowing"属性.它有什么作用?

解决方案

做了一些研究,发现 这个.显然,[Shadowing] 属性在 MSTest 创建允许您调用类上的私有方法的访问器类时使用,就好像它是公共的一样.>

因此,当您对目标类的私有方法进行单元测试时,您可以通过目标类的访问器包装类使用该私有方法.

When i generated unit tests the Visual studio added some fictive class that mocks my class and added the "Shadowing" attribute. What does it do?

解决方案

Did some research and found this. Apparantly, the [Shadowing] attribute is used by MSTest when it creates an accessor class that allows you to call a private method on a class as if it were public.

So when you're unit testing a private method of a target class, that private method will be available to you via the accessor wrapper class for the target class.

这篇关于VS 在生成单元测试时使用的 Shadowing 属性是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆