如何测试框架,如果单元测试是在单独的程序? [英] How to test Framework if Unit tests are in separate assembly?

查看:193
本文介绍了如何测试框架,如果单元测试是在单独的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于如何测试框架,如果单元测试是在单独的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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