Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从VB.NET测试用例访问私有成员?_Vb.net_Unit Testing - Fatal编程技术网

如何从VB.NET测试用例访问私有成员?

如何从VB.NET测试用例访问私有成员?,vb.net,unit-testing,Vb.net,Unit Testing,我正在使用VS2010专业版内置测试用例。我有一个类,它有一个只读属性,如下所示: Private _server As IServer = Nothing Public ReadOnly Property Server() Get If _server Is Nothing Then RemotingSetup.RegisterHttpBinaryChannel() _ser

我正在使用VS2010专业版内置测试用例。我有一个类,它有一个只读属性,如下所示:

    Private _server As IServer = Nothing
    Public ReadOnly Property Server()
        Get
            If _server Is Nothing Then
                RemotingSetup.RegisterHttpBinaryChannel()
                _server = RemotingFactory.CreateProxy(Of IServer)(Options.DevLocal)
            End If

            Return _server
        End Get
    End Property
在我的测试用例中,我想做一个假的服务器实现,这样我就可以测试一些类方法,而不必实际地攻击服务器。我环顾四周,看到了
InternalsVisibleTo
属性,但这似乎只允许访问
朋友
级别的成员


除了声明这些成员为Public/Friend之外,还有什么简单的方法可以访问这些成员吗?

除了使用一个模拟私有成员的模拟库(例如,我所知道的唯一一个这样做的库)之外,至少在直接测试这个特定类时,您运气不佳

还有其他的可能性-您可以从这个类中创建子类,并且只重写这个属性。这将允许您测试所有其他功能。当然,这假设类不是密封的(不可继承的)。

检查这个问题: