[Unit testing] Exception without the /nosiolation switch

J

Jerome Lague

Hi all,

I am a newbie in unit testing and i am facing an annoying issue.
My solution containes C#, C++/clr (C++/CLI), and C++ native. I would like to
test a C# project which has C++/clr dependency. My assembly is build from
severals netmodule, some writtens in C#, some in C++/CLI.

When I launch the test from Visual. I got an exception (see exception stack
below).
Actually, if I use mstest and /noisolation, IT WORKS!

I am not sure of understanding this magical argument. MSDN say : "Run tests
within the MSTest.exe process. This choice improves test run speed but
increases risk to the MSTest.exe
process".(http://msdn.microsoft.com/en-us/library/ms182489.aspx)

But in my case, there is not just a matter of speed! It affects the test
process.

So my questions are :
1) What excatly the noisolation does ?
2) How can I avoid the noisolation argument and sucessfully pass my tests ?
3) If the 2) isn't possible, how can I use noisolation arg in visual ?
4) What is the link between my exception and /noisolation ?

Thanks for your replies!

Error message:
Test method TestProject1.UnitTest2.TestMethod1 threw exception:
System.TypeInitializationException: Une exception a été levée par
l'initialiseur de type pour '<Module>'. --->
<CrtImplementationDetails>.ModuleLoadException: The C++ module failed to
load while attempting to initialize the default appdomain.
---> System.BadImageFormatException: The module was expected to contain an
assembly manifest. (Exception de HRESULT : 0x80131018).

Stack trace:
System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32
errorCode, IntPtr errorInfo)
DoCallBackInDefaultDomain(IntPtr function, Void* cookie) in
f:\dd\vctools\crt_bld\self_x86\crt\src\minternal.h: line 447
DoCallBackInDefaultDomain(IntPtr , Void* )
DefaultDomain.Initialize()
LanguageSupport.InitializeDefaultAppDomain(LanguageSupport* )
LanguageSupport._Initialize(LanguageSupport* )
LanguageSupport.Initialize(LanguageSupport* )
ThrowModuleLoadException(String errorMessage, Exception innerException) in
f:\dd\vctools\crt_bld\self_x86\crt\src\minternal.h: line 224
ThrowModuleLoadException(String , Exception )
LanguageSupport.Initialize(LanguageSupport* )
cctor()
TestProject1.UnitTest2.TestMethod1()

Fusion log viewer report concerning the guilty module:

*** Entrée du journal Binder d'assembly (05/06/2009 @ 11:16:22) ***

L'opération a échoué.
Résultat de liaison : hr = 0x80131018. Aucune description disponible.

Gestionnaire des assemblys chargé à partir de :
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Exécution sous l'exécutable c:\Program Files\Microsoft Visual Studio
9.0\Common7\IDE\vstesthost.exe
--- Un journal des erreurs détaillé suit.

JRN : liaison explicite IJW. Chemin d'accès au fichier :
C:\...\UnitTest\TestResults\Results\Out\InventorBase.netmodule.I notice that
when run with the /noisolation switch, I found no entry concerning the
netmodule (the fusion log settings is set to 'Log all binds to disk').It is
like if the netmodule was loaded as an assembly ...
 
G

Gregory A. Beamer

Hi all,

I am a newbie in unit testing and i am facing an annoying issue.
My solution containes C#, C++/clr (C++/CLI), and C++ native. I would
like to test a C# project which has C++/clr dependency. My assembly is
build from severals netmodule, some writtens in C#, some in C++/CLI.

When I launch the test from Visual. I got an exception (see exception
stack below).
Actually, if I use mstest and /noisolation, IT WORKS!

I am not sure of understanding this magical argument. MSDN say : "Run
tests within the MSTest.exe process. This choice improves test run
speed but increases risk to the MSTest.exe
process".(http://msdn.microsoft.com/en-us/library/ms182489.aspx)


Not 100% sure how to fix the issue, but interop is always problematic.
Overall, I would say that your unit tests are not really unit tests, as
you are testing more than just the code in a single method.

Perhaps using some form of dependency injection could help test the .NET
code without having to spin up all of the interop bits.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
J

Jerome Lague

Hi all,

Sorry for my latter feed back but I was in vacation ;-)
Interop is for sure a problematic factor.
I succeed in building a small test case which reproduced the exception.

In the module part of the final assembly, I have a static initializer block
for an object which belong to the C++ library I interop with.
If I remove the static block, the test is successfull even without the
/noisolation switch.
On the other side if I build the module as an assembly (with the static
block), the test is also successfull ...

Tested under Windows XP pro 32bits Visual Studio team edition 2008
 
J

Jerome Lague

Hi all,

Sorry for my latter feed back but I was in vacation ;-)
Interop is for sure a problematic factor.
I succeed in building a small test case which reproduced the exception.

In the module part of the final assembly, I have a static initializer block
for an object which belong to the C++ library I interop with.
If I remove the static block, the test is successfull even without the
/noisolation switch.
On the other side if I build the module as an assembly (with the static
block), the test is also successfull ...

Tested under Windows XP pro 32bits Visual Studio team edition 2008
 

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

Similar Threads


Top