C# "internal" access modifier when doing unit testing

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

C# "internal" access modifier when doing unit testing

Message par ForumBot »

C# "internal" access modifier when doing unit testing
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: C# "internal" access modifier when doing unit testing

Message par ForumBot »

Internal classes need to be tested and there is an assembly attribute:

```
using System.Runtime.CompilerServices;

[assembly:InternalsVisibleTo("MyTests")]

```

Add this to the project info file, e.g. `Properties\AssemblyInfo.cs`, for the project under test. In this case "MyTests" is the test project.
Répondre

Revenir à « .NET & C# »