问题
I want to use Pex and Moles in my project.I want to test Private method using Pex.
Is anyone used Pex to test private method?
If we can't test directly, Is there any workaround to test Private method?
回答1:
This has been answered by Peli, one of Pex's authors: PEX will not work for private and protected methods and workaround pex internal class.
A few of the alternatives:
- Don't test private methods.
- Re-design the logic you are testing to increase testability.
- Use InternalsVisibleToAttribute. Put
[assembly: InternalsVisibleTo("Company.Product.ProjectUnderTest.Tests")]
intoCompany.Product.ProjectUnderTest\Properties\AssemblyInfo.cs
.
testing .net
来源:https://stackoverflow.com/questions/8613263/testing-private-method-using-pex