I am working on unit tests for my project.
DLL with business logic should be built for .Net 2.0, but I would like to use Moq for testing (it requires .Net 3.5). That’s why I have moved all tests to separate .Net 3.5 project with reference to business logic project.
I need to test some methods, marked as internal from my test project. I can see the only way to do that using separate build configurations with conditional build symbols:
#if UNITTESTS
public
#else
internal
#endif
int DoSomeAction(int param1, int param2)
{
// some logic that need to be tested here
}
but such kind of code looks ugly. Maybe there is some better way, like mark method by some special attribute:
[ConditionalPublic("UNITTESTS")]
internal int DoSomeAction(int param1, int param2)
{
// some logic that need to be tested here
}
Thanks.
You can add the attribute
(it comes from System.Runtime.CompilerServices) to your project assembly.cs. Now your test project can access internals.
HTH