Testing Private Method using Pex

2019-07-30 08:36发布

问题:

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:

  1. Don't test private methods.
  2. Re-design the logic you are testing to increase testability.
  3. Use InternalsVisibleToAttribute. Put [assembly: InternalsVisibleTo("Company.Product.ProjectUnderTest.Tests")] into Company.Product.ProjectUnderTest\Properties\AssemblyInfo.cs.

testing .net



标签: pex