Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 65325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:55:44+00:00 2026-05-10T18:55:44+00:00

[ Of course, the question is not restricted to a specific friend implementation, feel

  • 0

[Of course, the question is not restricted to a specific ‘friend’ implementation, feel free though to point out implementation specifics if relevant]

Reading through the unanswered questions, I stumbled upon the InternalsVisibleTo attribute:

Specifies that types that are ordinarily visible only within the current assembly are visible to another assembly.

The C# Programming Guide on MSDN has a section Friend Assemblies describing how to use the attribute to allow the use of internal methods and types to another assembly.

I’m wondering whether it would be a Good Idea to use this to create a ‘hidden’ interface for instrumenting a library for use by the unit testing assembly. It seems to increase coupling massively in both directions (testing code in the production assembly, intimate internal knowledge about the production assembly in testing code), but on the other hand it might help in creating fine-grained tests without cluttering the public interface.

What is your experience with using friend declarations when testing? Was it your Silver Bullet, or did it start the Death March?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:55:44+00:00Added an answer on May 10, 2026 at 6:55 pm

    I’ve made extensive use of this technique – it means that my unit tests can test aspects of the code library that aren’t visible to normal consumers.

    While using [InternalsVisibleTo] does increase coupling, I believe the (minor) increase is well worth the gains.

    My unit tests are already tightly coupled to the code under test – though I try to write tests that assure specific outcomes, not specific implementations, by accessing things not visible to regular consumers, I do somewhat constrain the implementation.

    Going the other way, the coupling is minimal – in having the [InternalsVisibleTo] attribute on the code assembly, and in marking some things as internal instead of private (or protected internal instead of protected).

    (Note that I’m ignoring here any design changes that are provoked by the use of Unit Testing, which is a whole other discussion.)

    The [InternalsVisibleTo] attribute requires strong naming your assemblies. If you’re not doing this already, you may find this a bit burdensome as a strongly named assembly may only depend on other strongly named assemblies, which may end up with you needing to alter several assemblies.

    Getting the attribute right can be a bit fiddly, as it needs to include the public key of your test assembly. IDesign have a useful Friend Assembly tool that creates the attribute on your clipboard, ready for pasting. Recommended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 269k
  • Answers 269k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Class<String> c = String.class; Check out the Javadoc for java.lang.Class… May 13, 2026 at 1:14 pm
  • Editorial Team
    Editorial Team added an answer C# does not provide a file rename function, unfortunately. Anyhow,… May 13, 2026 at 1:14 pm
  • Editorial Team
    Editorial Team added an answer I was able to get Javadocs generated for all my… May 13, 2026 at 1:14 pm

Related Questions

I've edited and trimmed this to try and get it closed because the site
Currently, generics in C# do not allow any sane way to perform arithmetic. There
I am quite new to ICEfaces but already have experience with JSF/Facelets and the
My question is pretty straightforward: You are an executable file that outputs Access granted

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.