使用访问器进行单元测试 [英] Unit test with accessors

查看:42
本文介绍了使用访问器进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个由两部分组成的问题.

This is a two part question.

背景:我们将 C# 应用程序从 VS2005 移至 VS2008,并在此过程中将应用程序从 .net 2.0 移至 .net 3.5.除了单元测试之外,过渡进行得很顺利.

Background: We moved our C# application from VS2005 to VS2008 and in the process moved the application from .net 2.0 to .net 3.5. The transition went smoothly except for Unit Tests.

第一:单元测试框架是基于 Visual Studios 还是 .NET?

First: Is the unit test framework based off Visual Studios or .NET?

第二:这个问题源于我们在单元测试中遇到的问题.我们有需要访问器的内部类,以便对它们进行单元测试.当应用程序在 VS2005 中时,所有访问器都是通过右键单击所需的类并选择创建私有访问器"来自动创建的——这个访问器被放置在 VSCodeGenAccessors.cs 中.现在迁移到 VS2008 和 .net 3.5 后,访问器被放置在一个新创建的文件夹Test References"中,并为每个访问器创建一个文件 (.accessor)

Second: This question is derived from the issues we have with the unit tests. We have internal classes that need accessors in order to unit test them. When the application was in VS2005, all the accessors were auto created from right clicking on the desired class and selecting "Create Private Accessors" - this Accessor was placed in VSCodeGenAccessors.cs. Now after the migration to VS2008 and .net 3.5, the accessors are placed within a newly created folder "Test References" and for each accessor a file is created ( .accessor)

为了一致性起见,我如何将访问器生成到 VSCodeGenAccessors.cs 中.

How, for consistency sake, do I get the accessors to be generated into VSCodeGenAccessors.cs.

谢谢!

推荐答案

为了回答您的第一个问题,单元测试框架是某些版本的 Visual Studio 的一部分.公平:

To answer your first question, the unit test framework is a part of certain versions of Visual Studio. AFAIR:

  • Visual Studio 2005 团队系统
  • Visual Studio 2008 团队系统
  • Visual Studio 2008 专业版

关于你的第二个问题,恐怕我帮不上什么忙——我认为对内部进行单元测试是最糟糕的做法,所以我没有使用私有访问器的经验.

Regarding your second question I'm afraid I can't be of much help - I consider it a worst practice to unit tests internals, so I have no experience with the Private Accessors.

这篇关于使用访问器进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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