单元测试使用实际的类,而不是类的副本 [英] unit test to use actual classes and not copies of classes

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

问题描述

我目前在一个更大的系统软件创造了一些类单元测试/模块,采用Visual Studio 2008中的类的源文件都存储在一个存储库。当然,每当我将测试这些类,我将不得不选择将其包含在项目中的添加现有项,使我不得不说我会得到测试类的精确副本。这使得VS2008做出自己的类副本。但事实是,需求突然都在改变我必须用实际的类本身,而不是它们的副本(比如,放在测试项目的引用),这样,每当类将被编辑/修改/更新,单元测试一定会失败。我似乎无法找到任何选项,其中我的地方,在测试项目实际类的引用,并从那里,我想创建单元测试。有没有什么办法,其中我可以测试实际的类本身?

I'm currently creating unit tests for some classes/module in a much bigger system software, using Visual Studio 2008. The source files of the classes are stored in one repository. Of course, whenever I would test these classes, I would have to include them in the project by selecting the "Add Existing Item" so that I would have an exact copy of the class that I would get to test. This makes VS2008 make its own copy of the class. But the thing is, requirements suddenly have changed in that I have to use the actual classes themselves, and not copies of them (like, put a reference in the test project), so that whenever the classes would be edited/changed/updated, the unit test would surely fail. I can't seem to find any options wherein I'd place a reference to the actual classes in the test project, and from there, I'd create the unit test. Is there any way wherein I could test the actual classes themselves?

推荐答案

关键是将文件添加为纽带(东西就像一个快捷方式):

The key is to add the files as a link (something like a shortcut):

添加现有项>添加链接

见截图:

这样的Visual Studio不会让副本这些文件,如果原始出处改变他们,他们也将在您的解决方案进行修改。

That way Visual Studio won't make a copy of the files, and if you change them in the original source, they will also be modified in your Solution.

这篇关于单元测试使用实际的类,而不是类的副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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