如何用最小起订量框架编写的私有方法的单元测试在C#中? [英] How to write unit test for private method in c# using moq framework?

查看:148
本文介绍了如何用最小起订量框架编写的私有方法的单元测试在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用最小起订量框架编写的私有方法的单元测试在C#中,我已经在计算器和谷歌搜索,但我无法找到预期的结果。如果可以请帮我。

I want to write unit test for private method in C# using moq framework, I've search in StackOverFlow and Google, but I cannot find the expected result. Please help me if you can.

推荐答案

您不能,至少不会与起订量。

You can't, at least not with Moq.

但更重要的是,你的不应该的。
首先,你不测试的方法的,你测试的行为的。其次,为了测试的行为,你锻炼一类的的公共的API,并验证锻炼的结果。

But more importantly, you shouldn't. First off, you don't test methods, you test behaviours. Second, in order to test behaviours, you exercise a type's public API and verify the outcomes of that exercise.

私有方法的实现细节。你不希望验证的如何的事情得到完成,要验证事情的的得到完成。

Private methods are implementation details. You don't want to verify how things get done, you want to verify that things do get done.

这篇关于如何用最小起订量框架编写的私有方法的单元测试在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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