如何测试框架,如果单元测试是在单独的程序?是在、框架、单元测试、测试

2023-09-06 22:02:43 作者:ベ純情、小莮子

我组装我的框架和组装测试。但是,我需要测试内部类或替换某些服务。 例如, - 我需要测试的内部帮手。 - 我的框架阅读和分析其他应用程序创建的文件。我手动为测试创建这些文件。但我不能把它从单独的程序我的框架。我需要创建模拟的内部服务来提供这些文件。

I have assembly with my framework and assembly with tests. But I need to test internal classes or substitute some services. For example, - I need to test internal helper. - My framework read and analyze files created by other application. I create these files manually for tests. But I can't give it to my framework from separate assembly. I need to create mock for internal service to provide these files.

推荐答案

如果你希望你的内部类是可见的,以你的测试,你必须使你的测试组件的框架组件的朋友。

If You want Your internal classes to be visible to your tests You must make your test assembly a friend of your framework assembly.

您必须添加

[assembly: InternalsVisibleTo("MyTestAssembly")]

在你的框架集。

下面是一个朋友介绍组件链接到MSDN文档 - http://bit.ly/FriendAssemblies

Here is a link to MSDN Documentation about friend assemblies - http://bit.ly/FriendAssemblies