BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Friend Assemblies and Unit Testing

Friend Assemblies and Unit Testing

Bookmarks
One of the major problems with unit testing is the need to access non-public classes and methods. There are numerous ways to work around this such as using proxy classes and reflection, but wouldn't it be nicer if an assembly could just treat non-public fields as if they were public?

C# 2.0 has this ability via friend assemblies. Normally types marked as internal as only accessible from within the assembly that defines it. However, when an assembly says that another assembly is a friend via the InternalsVisibleTo attribute, that second assembly can access any type in the first one that is marked internal.

According to Tim Ng, the ability to define friend assemblies will be added to the next version of Visual Basic.

Rate this Article

Adoption
Style

BT