如何访问类的另一个组装单元测试的目的呢? [英] How to access classes in another assembly for unit-testing purposes?

查看:139
本文介绍了如何访问类的另一个组装单元测试的目的呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跳进单元测试的Visual-Studio 2008的方式,我不知道什么是实现跨组装的最佳方式用于测试目的的访问

I'm jumping into unit-testing the Visual-Studio 2008 way, and I'm wondering what's the best way to accomplish cross-assembly class access for testing purposes.

基本上,我有一个解决方案两个项目:

Basically, I have two projects in one solution:


  1. MyProject的( C#)

  2. MyProjectTests(C#测试项目)

在MyProject的一切目前有默认的可访问性,这如果我没有记错表示一切有效内部。我主要看水平测试,但也有少数代表参与。

Everything in MyProject currently has default accessibility, which if I recall correctly means everything is effectively internal. I'm mostly looking to test at the class level, but there are a few delegates involved.

有可能会是一个外部API在将来某个时候,但我的方式约20%提供了完整的(至少在纸面上)和我得到漂亮的持怀疑态度分层对这个未经测试的核心之上更多的代码。因此我想获得一些测试现在完成了,之前的应用程序是传统的足够完整(读:坏的和/或懒惰),功能测试和绝对的版本n + 1外部API是之前

There will probably be an external API sometime in the future, but I'm about 20% of the way to feature complete (at least on paper) and I'm getting pretty leery of layering more code on top of this untested core. Accordingly I'd like to get some testing done now, before the app is complete enough for traditional (read: bad and/or lazy) functional testing and definitely before the version n+1 external API is up.

在除了直接的答案,该解决方案的一个例子,将不胜感激。

In addition to a straight answer, an example of the solution would be greatly appreciated.

推荐答案

您可以使用集级属性 InternalsVisibleToAttribute 以实现这一目标。

You can use assembly-level attribute InternalsVisibleToAttribute to achieve this.

添加

[assembly:InternalsVisibleTo("MyProjectTests")]

在你MyProject的装配的AssemblyInfo.cs。

to AssemblyInfo.cs in your MyProject assembly.

这篇关于如何访问类的另一个组装单元测试的目的呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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