One of the challenges when performing unit tests in .NET is that the methods we want to test need to be public.
However, on many occasions, we will want to apply unit tests to methods defined as Internal. In this case, we will not be able to perform unit tests.
Fortunately, we can make Internal methods Public for certain assemblies, which we will call “Friend Assemblies”.
To do this, we must edit the project file we want to test. Inside, we will add the following line, replacing ‘MyAssemblyTests’ with the name of the Test project assembly.
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>MyAssemblyTests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
So, for example, the project file would look like this.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>MyAssemblyTests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
With this, we achieve that the Internal methods of our project will be public for the Test project, and we will be able to perform Unit Tests on them.

