I would like my Core assembly to not expose a certain class and I would still like to be able to test it. How can I do that ?
Writing unit tests for internal classes ensures that they behave correctly in their own world at least and we can have integration tests to test the correctness of whole application. Even if there are some redundant unit tests, it is better than having missing test cases at the top level.
internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.
A friend assembly is an assembly that can access another assembly's internal (C#) or Friend (Visual Basic) types and members. If you identify an assembly as a friend assembly, you no longer have to mark types and members as public in order for them to be accessed by other assemblies.
You can mark a friend assembly using the [assembly: InternalsVisibleTo(...)] attribute.
InternalsVisibleTo attribute to the rescue!
Just add:
[assembly:InternalsVisibleToAttribute("UnitTestAssemblyName")]
to your Core classes AssemblyInfo.cs file
See Friend Assemblies (C# Programming Guide) for best practices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With