English 中文(简体)
如何利用思考在议会内部测试一个内部(VB)级,而内部内部考试并不是一种选择?
原标题:How to use reflection to unit-test an internal (Friend in VB) class within an assembly, when the InternalsVisibleToAttribute is not an option?

我有以下两个项目的解决办法:

Company.Project.vbproj
Company.Project.Tests.vbproj

在<代码>Company. Project.vbproj内 一组:<代码>FriendClass.vb,范围为Friend(C#)

现在,我要从<条码>Company. Project. 试验s.vbproj组装中测试这一条。 I knowledge about the InternalsVisible ToAttribute,但这不是一个选项,因为只有C在2.NET中(quirestosupreack_com/quest-/28275)。

我想在我的测试组内,用这一内部的FriendClass

www.un.org/Depts/DGACM/index_spanish.htm 任何想法或已知做法?

提前感谢!

最佳回答

我发现的唯一工作是“NET”框架1.1中所用的工作。

由于 不能在......中使用。 NET 2.0 视觉基础是我发现的唯一工作,就是将我的测试纳入与我的图书馆本身相同的项目。 此外,还需要完成一些进一步的工作。

  1. Create yourself a new compilation CONFIG called "Tests" (that is where you may select "Release"/"Debug");
  2. Create a new folder named "Tests" within your project;
  3. Add a new class, the one to test your Friend (internal in C#) members;
  4. First line of code within this class should be: #if CONFIG = "Tests" then ... #end if;
  5. Place your code between this compiler IF directive.

例如,如果我有以下友好班:

Friend Class MyFactory
    Friend Property Property1 As Object
        Get
            Return _field1
        End Get
        Set (ByVal value As Object)
            _field1 = value
        End Set
    End Property

    Friend Sub SomeSub(ByVal param1 As Object)
          Processing here...
    End Sub
End Class

然后,如果你想用2.NET 2.0 视力基础测试这一类别,你将需要在<代码”的同一项目内设立一个测试班。 MyFactory等舱座。 这一类人应如此:

#If CONFIG = "Tests" Then

    Imports NUnit.Framework

    <TestFixture()> _
    Public Class MyFactoryTests
        <Test()> _
        Public Sub SettingProperty1Test
              Doing test here...
        End Sub
    End Class

#End If

由于你们有一份编辑指令,告诉汇编者,只有在选择了“测试”CONFIG时,才能汇编和列入这一类别,因此,你就没有按照“选择”或“释放”模式获得这一类别。 这门课程甚至成为图书馆的一部分,因为不一定会污染你的图书馆,这使你能够测试你的友善班。

这是我发现在“视力基本面”2.0中围绕这一问题展开工作的最新方法。

问题回答

暂无回答




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签