VS 在生成单元测试时使用的 Shadowing 属性是什么? [英] What is the Shadowing attribute that the VS uses when it generates unit tests?
问题描述
当我生成单元测试时,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屋!