使用Pex测试私有方法 [英] Testing Private Method using Pex

查看:156
本文介绍了使用Pex测试私有方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在项目中使用Pex和Moles.我想使用Pex测试Private方法.

I want to use Pex and Moles in my project.I want to test Private method using Pex.

有人用Pex测试私有方法吗?

Is anyone used Pex to test private method?

如果我们不能直接测试,是否有任何变通办法来测试私有方法?

If we can't test directly, Is there any workaround to test Private method?

推荐答案

已由 Peli (其中之一)回答Pex的作者: PEX不适用于私有和受保护的方法解决方法pex内部类.

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.

一些替代方法:

  1. 不要测试私有方法.
  2. 重新设计要测试的逻辑以提高可测试性.
  3. 使用 InternalsVisibleToAttribute .将[assembly: InternalsVisibleTo("Company.Product.ProjectUnderTest.Tests")]放入Company.Product.ProjectUnderTest\Properties\AssemblyInfo.cs.
  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.

的问题

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆