Testing Private Method using Pex

2019-07-30 08:04发布

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?

标签: pex
1条回答
聊天终结者
2楼-- · 2019-07-30 09:00

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.

查看更多
登录 后发表回答