I need xUnit to work with internal test classes. The problem is that I have used a generic base test fixture UnitTestBase. So I create my fixture as
class MyFixture: UnitTestBase<SomeSystemUnderTheTest>
{
...
}
In some cases SomeSystemUnderTheTest appears to be internal class. Lets call it SomeSystemUnderTheTestInternal. As result UnitTestBase<SomeSystemUnderTheTestInternal> also appear to be internal even if UnitTestBase public. As result of that I can't specify MyFixture to be public as compiler says your base class has less accessibility. So MyFixture in my case only can be internal, but then xUnit requires it to be public. Is there a workaround to make xUnit work with internal fixtures?
SomeSystemUnderTheTest is a class which implements some interface. It is not used directly anywhere it is just got injected by DI container. It was marked as internal. I have slightly simplified our situation above, SomeSystemUnderTheTest is in fact derived from a generic class SomeSystemUnderTheTestBase, where SomeInternalClass is an internal class and as result of this the whole tree is internal. I can't change it as it is not something we wanna do.
Add this just above the namespace declaration in your SomeSystemUnderTestInternal file:
[assembly: InternalsVisibleToAttribute("TestProject")]
Where TestProject is the assembly name of the project that contains your test class.
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