C# "internal" access modifier when doing unit testing

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

C# "internal" access modifier when doing unit testing

Message par Clippy »

C# "internal" access modifier when doing unit testing
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

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

Message par Clippy »

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# »