如何使用 NUnit 测试私有方法? [英] How do you test private methods with NUnit?

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

问题描述

我想知道如何正确使用 NUnit.首先,我创建了一个单独的测试项目,使用我的主项目作为参考.但在那种情况下,我无法测试私有方法.我的猜测是我需要将我的测试代码包含在我的主代码中?!- 这似乎不是正确的做法.(我不喜欢发布带有测试的代码的想法.)

I am wondering how to use NUnit correctly. First, I created a separate test project that uses my main project as reference. But in that case, I am not able to test private methods. My guess was that I need to include my test code into my main code?! - That doesn't seem to be the correct way to do it. (I dislike the idea of shipping code with tests in it.)

如何使用 NUnit 测试私有方法?

How do you test private methods with NUnit?

推荐答案

通常,单元测试针对的是类的公共接口,理论上实现是无关紧要的,只要结果从客户端的角度来看是正确的.

Generally, unit testing addresses a class's public interface, on the theory that the implementation is immaterial, so long as the results are correct from the client's point of view.

因此,NUnit 不提供任何测试非公开成员的机制.

So, NUnit does not provide any mechanism for testing non-public members.

这篇关于如何使用 NUnit 测试私有方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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