Unit Test: Internal Type versus public
In this post, I’d like to explain how to use the internal type instead of public during the test phase.
I don’t spent a lot of words, so I share you the inital point. In your solution, you have two projects:
Is it simple? YES!
Internal vs Public
In “MyIdea” you have the full logic on your project. In the following lines, you can see a fake class
MyIdeaFakeClass is a specific class for this project, for this reason I don’t want to use public.
In this way I have a problem in my unit test project. I cannot use the following code:
The reason is very simple:
|‘MyIdeaFakeClass’ is inaccessible due to its protection level
❌ ‘MyIdeaFakeClass’ is inaccessible due to its protection level
How can I solve this?
If you want to solve this exception you have two ways:
- change internal to public (bad idea)
- edit the project
In this post, I teach you how to change the file project (csproj)
Now, you can only save the csproj and the error CS0122 doesn’t block your work.
♻️ Did you know this tip? Share it with your friends!