Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xUnit test class internal

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.

like image 534
Alex K Avatar asked Oct 31 '25 08:10

Alex K


1 Answers

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.

like image 108
Shafiq Jetha Avatar answered Nov 01 '25 23:11

Shafiq Jetha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!