私立课程方法单元 [英] Nunit for Methods in private class

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

问题描述

大家好,

我需要为私有类中的方法编写nunit测试用例
我尝试过这种方式,但对我不起作用.

... [程序集:System.Runtime.CompilerServices.InternalsVisibleTo("ATests")] ...

还有其他方法可以编写nunit测试用例吗?

hi folks,

i need to write nunit test cases for the methods inside the private class
i tried this way, but it doesnt work for me.

...[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("ATests")]...

is there is any other way to do write nunit test cases?

推荐答案



我在MS单元测试用例中使用了Private对象.对NUnit不太了解,但这也可能对您有用.

尝试使用 PrivateObject 类访问私有对象以进行测试.

在下面的链接中,我列出了一些有关访问私有对象的信息.

为您的C#代码创建单元测试 [ ^ ]

祝您好运
Hi,

I have used Private objects in MS Unit test cases. do not have much idea about NUnit but this may work for you as well.

Try to use PrivateObject class to access private object for testing.

In below link i have list out some information on accessing private object.

Creating Unit tests for your c# code[^]

Best luck


此处是NUnit TestCase Generator的链接
NUnit测试案例代码生成器 [
Here''s The Link for NUnit TestCase Generator
NUnit Test Case Code Generator[^]


您需要反射"-对象实例化和方法调用必须通过反射来完成.它不像使用MSTest那样容易,但是可以完成.
You need "Reflection" - object instantiation and method calls have to be done via reflection. It is not such easy as with MSTest, but it can be done.


这篇关于私立课程方法单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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