Unit testing

G

Guest

Please can you show me how to unit test the following class...

Friend Delegate Sub Delegate1()

Friend Class Class1

Private m_Delegate1 As Delegate1

Friend WriteOnly Property Delegate1() As Delegate1
Set(ByVal value As Delegate1)
Me.m_Delegate1 = value
End Set
End Property

Friend Sub Sub1()
Me.m_Delegate1.Invoke()
End Sub

End Class

I want my test to look something like this...

Public Sub Test()

Dim target As Object = Class1Accessor.CreatePrivate

Dim val As Delegate1Accessor = New Delegate1Accessor(AddressOf MySub)

Dim accessor As Class1Accessor = New Class1Accessor(target)

accessor.Delegate1 = val
accessor.Sub1()

End Sub

Public Sub MySub()
Stop
End Sub
 
K

Kevin Yu [MSFT]

Hi Richard,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi Richard,

I'm not quite sure what do you mean by Class1Accessor.CreatePrivate? Could
you explain it with a little more details?

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Hi Kevin.

Class1Accessor.CreatePrivate creates an object from the private class
"Class1".

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VSENT.v80.en/dv_vsetlt01/html/f6cc7fc2-c43c-4b0c-ba4e-60755cc39e28.htm
explains how to create unit tests for private members.
 
K

Kevin Yu [MSFT]

Hi Richard,

Sorry for the late response, but your code seems to be fine. I used the
code generator to generate test code. It looks like the following which
seems to be the same as the code you have provided.

<DeploymentItem("WindowsApplication85.exe"), _
TestMethod()> _
Public Sub Delegate1Test()
Dim target As Object =
WindowsApplication85_Class1Accessor.CreatePrivate

Dim val As WindowsApplication85_Delegate1Accessor = New
WindowsApplication85_Delegate1Accessor(AddressOf MySub) 'TODO: Assign to an
appropriate value for the property

Dim accessor As WindowsApplication85_Class1Accessor = New
WindowsApplication85_Class1Accessor(target)

accessor.Delegate1 = val

Assert.Inconclusive("Write-only properties cannot be verified.")
End Sub

Are you testing the delegate? Do you have any concerns on this? Please feel
free to let me know.

Kevin Yu
Microsoft Online Community Support

============================================================================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
============================================================================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top