473,785 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Testing Private Types

I have some simple (private) types...

Friend Enum Types
Value1
Value2
End Enum

Friend Structure Detail
Dim Type As Types
End Structure

Friend Class Parser
Friend Function GetDetail() As Detail
Dim _Detail As New Detail
_Detail.Type = Types.Value2
Return _Detail
End Function
End Class

I hope to test the Parser.GetDetai l method with the following test but I
can't see how to set the _ExpectedDetail .Type...

<TestClass()> Public Class ParserTest

<TestMethod() > Public Sub GetDetailTest()

Dim _Parser As ClassLibrary1_P arserAccessor = New
ClassLibrary1_P arserAccessor(C lassLibrary1_Pa rserAccessor.Cr eatePrivate)

Dim _ExpectedDetail As ClassLibrary1_D etailAccessor = New
ClassLibrary1_D etailAccessor(C lassLibrary1_De tailAccessor.Cr eatePrivate)

'_ExpectedDetai l.Type = ClassLibrary1_T ypesAccessor.Va lue2
'_ExpectedDetai l.Type = New
ClassLibrary1_T ypesAccessor(Cl assLibrary1_Typ esAccessor.Valu e2)
'_ExpectedDetai l.Type = ???

Dim _ActualDetail As ClassLibrary1_D etailAccessor = _Parser.GetDeta il

Assert.AreEqual (_ExpectedDetai l.Type, _ActualDetail.T ype)

End Sub

End Class

Jun 28 '06 #1
7 1501
You can test the friends by embedding your test stubs, although this is not
a "best practice". You can also test with reflection, which is what Team
System does. I do not have the details (i.e. code samples), but I might be
able to find the bandwidth to reverse engineer a Team System test on a
method not publicly exposed.

--
Gregory A. Beamer

*************** *************** *************** ****
Think Outside the Box!
*************** *************** *************** ****
"Dick" <Ri***********@ nospam.nospam> wrote in message
news:3D******** *************** ***********@mic rosoft.com...
I have some simple (private) types...

Friend Enum Types
Value1
Value2
End Enum

Friend Structure Detail
Dim Type As Types
End Structure

Friend Class Parser
Friend Function GetDetail() As Detail
Dim _Detail As New Detail
_Detail.Type = Types.Value2
Return _Detail
End Function
End Class

I hope to test the Parser.GetDetai l method with the following test but I
can't see how to set the _ExpectedDetail .Type...

<TestClass()> Public Class ParserTest

<TestMethod() > Public Sub GetDetailTest()

Dim _Parser As ClassLibrary1_P arserAccessor = New
ClassLibrary1_P arserAccessor(C lassLibrary1_Pa rserAccessor.Cr eatePrivate)

Dim _ExpectedDetail As ClassLibrary1_D etailAccessor = New
ClassLibrary1_D etailAccessor(C lassLibrary1_De tailAccessor.Cr eatePrivate)

'_ExpectedDetai l.Type = ClassLibrary1_T ypesAccessor.Va lue2
'_ExpectedDetai l.Type = New
ClassLibrary1_T ypesAccessor(Cl assLibrary1_Typ esAccessor.Valu e2)
'_ExpectedDetai l.Type = ???

Dim _ActualDetail As ClassLibrary1_D etailAccessor =
_Parser.GetDeta il

Assert.AreEqual (_ExpectedDetai l.Type, _ActualDetail.T ype)

End Sub

End Class

Jun 28 '06 #2
Thanks Gregory.

Visual Studio neatly creates the necessary classes to test my private
members. The lines in my example "Dim _Parser As..." and "Dim _ExpectedDetail
As..." construct special accessor objects that VS defines. These allow access
to my private objects and allow me to test most of their members.

However, I can't see how to test (i.e. set) a property on one of these
accessor objects when the property itself is typed using another private
type. The two commented lines in my example "ExpectedDetail .Type = ..." show
a couple of attempts that I had at this, but both fail with exceptions!

"Cowboy (Gregory A. Beamer)" wrote:
You can test the friends by embedding your test stubs, although this is not
a "best practice". You can also test with reflection, which is what Team
System does. I do not have the details (i.e. code samples), but I might be
able to find the bandwidth to reverse engineer a Team System test on a
method not publicly exposed.

--
Gregory A. Beamer

*************** *************** *************** ****
Think Outside the Box!
*************** *************** *************** ****
"Dick" <Ri***********@ nospam.nospam> wrote in message
news:3D******** *************** ***********@mic rosoft.com...
I have some simple (private) types...

Friend Enum Types
Value1
Value2
End Enum

Friend Structure Detail
Dim Type As Types
End Structure

Friend Class Parser
Friend Function GetDetail() As Detail
Dim _Detail As New Detail
_Detail.Type = Types.Value2
Return _Detail
End Function
End Class

I hope to test the Parser.GetDetai l method with the following test but I
can't see how to set the _ExpectedDetail .Type...

<TestClass()> Public Class ParserTest

<TestMethod() > Public Sub GetDetailTest()

Dim _Parser As ClassLibrary1_P arserAccessor = New
ClassLibrary1_P arserAccessor(C lassLibrary1_Pa rserAccessor.Cr eatePrivate)

Dim _ExpectedDetail As ClassLibrary1_D etailAccessor = New
ClassLibrary1_D etailAccessor(C lassLibrary1_De tailAccessor.Cr eatePrivate)

'_ExpectedDetai l.Type = ClassLibrary1_T ypesAccessor.Va lue2
'_ExpectedDetai l.Type = New
ClassLibrary1_T ypesAccessor(Cl assLibrary1_Typ esAccessor.Valu e2)
'_ExpectedDetai l.Type = ???

Dim _ActualDetail As ClassLibrary1_D etailAccessor =
_Parser.GetDeta il

Assert.AreEqual (_ExpectedDetai l.Type, _ActualDetail.T ype)

End Sub

End Class


Jun 28 '06 #3
Hello,

I think you may set the expected value directly with the enum values, for
example:

Assert.AreEqual (ClassLibrary1_ TypesAccessor.V alue2, _ActualDetail.T ype)

Can this help on the issue?

Luke Zhang
Microsoft Online Community Lead

=============== =============== =============== =====
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.)

Jun 29 '06 #4
Hi Luke

Although this works it doesn't quite do what I want.

I want to test the detail object as a whole, not test each property
separately, i.e. I want to do...

Assert.AreEqual (_ExpectedDetai l, _ActualDetail)

....not...

(Pseudo code)
For Each Property in _ExpectedDetail .Properties
Assert.AreEqual (Property, ActualDetail.Co rrespondingProp erty)
Next Property

This doesn't matter so much in my example because the Detail type only has
one member but in my real problem it has many members.

Do you have any other suggestions?

"Luke Zhang [MSFT]" wrote:
Hello,

I think you may set the expected value directly with the enum values, for
example:

Assert.AreEqual (ClassLibrary1_ TypesAccessor.V alue2, _ActualDetail.T ype)

Can this help on the issue?

Luke Zhang
Microsoft Online Community Lead

=============== =============== =============== =====
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.)

Jun 29 '06 #5
Or you may add a method in the structure/class to set internal fields, like:

Friend Structure Detail
Dim Type As Types

Friend Sub SetType(ByVal value As Types)

Type = value
End Sub

End Structure

In the Unit Test code:

_ExpectedDetail .SetType(ClassL ibrary1_TypesAc cessor.Value2)

Regards,

Luke Zhang
Microsoft Online Community Lead

=============== =============== =============== =====
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.)

Jun 30 '06 #6
OK that works although it isn't ideal because I have to change the primary
class to facilitate the test class.

Can you explain why setting the Type member directly (i.e.
_ExpectedDetail .Type = ClassLibrary1_T ypesAccessor.Va lue2) doesn't work?

"Luke Zhang [MSFT]" wrote:
Or you may add a method in the structure/class to set internal fields, like:

Friend Structure Detail
Dim Type As Types

Friend Sub SetType(ByVal value As Types)

Type = value
End Sub

End Structure

In the Unit Test code:

_ExpectedDetail .SetType(ClassL ibrary1_TypesAc cessor.Value2)

Regards,

Luke Zhang
Microsoft Online Community Lead

=============== =============== =============== =====
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.)

Jun 30 '06 #7
Hello,

Thank you for the confirmation. Regarding the question
"_ExpectedDetai l.Type" is defined as ClassLibrary1_T ypesAccessor, but
ClassLibrary1_T ypesAccessor.Va lue2 is actually ClassLibrary1.T ypes (got
from Microsoft.Visua lStudio.TestToo ls.UnitTesting. PrivateObject with
reflection). So, it cannot be assigned the value directly.

Luke Zhang
Microsoft Online Community Lead

=============== =============== =============== =====
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.)

Jul 3 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2307
by: Andrew | last post by:
Hi, I am thinking about ways for efficient techniques for isolation testing. Here is the problem as I see it: Complex OO systems are designed with massive number of dependencies between modules and classes. In most cases these dependencies end-up in external systems such as databases and OS. Overhead in designing systems with "could be stubbed" in mind is great, so in many cases dropped. I would appreciate if anyone interested in this...
4
510
by: Nathon Dalton | last post by:
I need to know what the appropriate way to test for nothing in several different types of data types is. Here are some examples For string I use this If Not abc.text Is Nothing AndAlso Not abc.text = "" The ' Some Cod End I For datetime's I'm currently using something like this If Not abc.ToShortDateString = "01/01/0001" The ' Some Cod
3
2702
by: SnaiL | last post by:
Hi, guys. I am interested in C++ unit testing. I know only two methods how to test private class methods. 1) Declare friend class in the code. But I don't like this style because tests depends on the code. 2) Cheat compiler. We can do it by: #define private public #include "..."
5
2734
by: Brian | last post by:
Hello all.. Am working on an Air Hockey game... have an table loaded into a picture box. The borders of the table are slightly slanted. Am using hit testing lines with GDI+ to manipulate the puck moving around. I want the puck is bounce when it hits a border (specified by the hitlines). Retreieved some info on hit testing lines from Bob Powell's GDI+ FAQ (very useful!) but i'm fairly new at the idea of hit testing and am
6
1394
by: Primera | last post by:
I'm looking for the best way to test individual methods and such during development. I use VS2005, but am still new to .NET. I'd like to test things as I develop without executing the entire app etc. Thanks
72
5282
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: http://geosoft.no/development/unittesting.html Thanks.
18
2400
by: Andrew Wan | last post by:
I have been developing web applications with ASP & Javascript for a long time. I have been using Visual Studio 2003.NET. While VS2003 is okay for intellisense of ASP & Javascript, it's still not that great. One of the cons of ASP & Javascript is that they're both interpreted, which means one has twice the amount of work to do interms of syntax checking & semantic/runtime checking. Another bad thing is that ASP & Javascript doesn't have...
14
1563
by: Karsten Dambekalns | last post by:
Hi. Thomas Mlynarczyk wrote: Why do you want them to be private in the first place? I have yet to see code where this really makes sense... And if it does, then the external public API is what counts, if the code as a whole still delivers what it promises, and that can be tested, it should be fine.
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.