473,472 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Unit Tests and COM Exceptions

Hi,

Sorry I am bringing this topic again, but something does not feel
right:
I am trying to use VS 2005 unit test to prove that a COM component that
I use is throwing the right COM exception. So I am trying this

try
{
COMComponent.GenerateCOMException(); // this throws the COM
exception
}
catch (System.Runtime.InteropServices.COMException e)
{
// this should show the HRESULT of the COM exception....
MessageBox.Show(e.ErrorCode.ToString());
}

However, as soon as the exception is generated, the unit test fails and
does non even go to the catch statement - exits immediately. Funny
thing is that if I use a generic exception like catch (System.Exception
e), it DOES go to the catch statement. However, the generic exception
does not give me the ErrorCode, which is a member of COMException only.
If i try the ExpectedException attribute, as soon as it generates the
exception, it exits, again without reaching the catch statement, this
time with Passed result...

Does anyone have any idea what is going on....?

Thanks,

Ivan

Nov 18 '06 #1
2 1078
>However, as soon as the exception is generated, the unit test fails and
does non even go to the catch statement - exits immediately. Funny
thing is that if I use a generic exception like catch (System.Exception
e), it DOES go to the catch statement. However, the generic exception
does not give me the ErrorCode, which is a member of COMException only.
If i try the ExpectedException attribute, as soon as it generates the
exception, it exits, again without reaching the catch statement, this
time with Passed result...

Does anyone have any idea what is going on....?

Some HRESULTs are mapped to specific .NET exception types and not to
the generic COMException. For those you can use
Marshal.GetHRForException().
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 18 '06 #2
I believe that Win32Exception has some very helpful methods. Check into the
docs for it.

"ba******@gmail.com" wrote:
Hi,

Sorry I am bringing this topic again, but something does not feel
right:
I am trying to use VS 2005 unit test to prove that a COM component that
I use is throwing the right COM exception. So I am trying this

try
{
COMComponent.GenerateCOMException(); // this throws the COM
exception
}
catch (System.Runtime.InteropServices.COMException e)
{
// this should show the HRESULT of the COM exception....
MessageBox.Show(e.ErrorCode.ToString());
}

However, as soon as the exception is generated, the unit test fails and
does non even go to the catch statement - exits immediately. Funny
thing is that if I use a generic exception like catch (System.Exception
e), it DOES go to the catch statement. However, the generic exception
does not give me the ErrorCode, which is a member of COMException only.
If i try the ExpectedException attribute, as soon as it generates the
exception, it exits, again without reaching the catch statement, this
time with Passed result...

Does anyone have any idea what is going on....?

Thanks,

Ivan

Nov 20 '06 #3

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

Similar topics

4
by: Edvard Majakari | last post by:
Greetings, fellow Pythonistas! I'm about to create three modules. As an avid TDD fan I'd like to create typical 'use-cases' for each of these modules. One of them is rather large, and I wondered...
38
by: Christoph Zwerschke | last post by:
In August 2001, there was a thread about the "Art of Unit Testing": http://groups.google.com/group/comp.lang.python/browse_frm/thread/aa2bd17e7f995d05/71a29faf0a0485d5 Paul Moore asked the...
14
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
16
by: Greg Roberts | last post by:
Hi I want to place the tests needed in the code using attributes. There seems to be enough code snippets around for me to cover this. e.g. // Test cases, run these here on the function and...
72
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: ...
6
by: Dick | last post by:
I’d appreciate some advice regarding unit tests. My questions are general in nature but (as usual) best conveyed via a (simplified) example: I have a table that contains two columns – the...
1
by: rich_sposato | last post by:
I released version 2.0 of C++ Unit Test Library. You can download it from SourceForget.Net at http://sourceforge.net/projects/cppunittest/ .. I wrote this unit test library because other unit...
6
by: Vyacheslav Maslov | last post by:
Hi all! I have many many many python unit test, which are used for testing some remote web service. The most important issue here is logging of test execution process and result. I strongly...
10
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about...
3
by: IanWright | last post by:
I'm currently in the process of writing a class library, and I'm attempting to write as many unit tests as possible to ensure that I can weed out all the mistakes early on. Part of this involves...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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 ...
0
muto222
php
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.