单元测试C#保护方法 [英] Unit testing C# protected methods

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

问题描述

我来自Java EE的世界,但现在我工作的一个.NET项目。在Java中,当我想测试一个受保护的方法,这是很容易的,只是有测试类相同的包名就足够了。 是否有任何类似的C#?是否有单元测试的保护方法有什么好的做法?我只找到框架和人们说我应该测试唯一的公共方法。 它应该有可能做到这一点而没有任何框架...

I come from the Java EE world but now I'm working on a .Net project. In Java when I wanted to test a protected method it was quite easy, just having the test class with the same package name was enough. Is there anything similar for C#? Is there any good practice for unit testing the protected methods? I only found frameworks and people saying that I should test only public methods. It should be possible to do it without any framework...

多谢了。

推荐答案

您可以继承类,你要测试你的测试类。

You can inherit class you are testing on your test class.

public class Test1 : SomeClass{ Asert.AreEqual(1,SomeClass.ProtectedMethod());}

这篇关于单元测试C#保护方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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