Re: Testing a Singleton with NUnit

"Charlie Poole" <[email protected]> Tue, 29 Jul 2008 11:34:26 -0700
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <008f01c8f1a9$c59eb9e0$6401a8c0@ferrari>
Hi Christian,

Well, you picked the right list, which puts you ahead of
many people. :-)

What does the implementation of getInstance() look like?

Charlie 

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf 
> Of Christian Jordan
> Sent: Tuesday, July 29, 2008 11:29 AM
> To: [email protected]
> Subject: [Nunit-users] Testing a Singleton with NUnit
> 
> Hello everybody,
> 
> this is the first time I use this mailing list and I 
> apologise for any inconvenience if I overlooked an archived 
> Mailing-Entry that matches my problem :-))
> 
> The situation:
> 
> I'm using NUnit 2.4.8 .NET 2.0 with Visual Basic 2005.
> I want to test a method which is located in a Class that 
> implements the Singleton-Pattern. The test class looks like this:
> 
> Imports NUnit.Framework
> Imports --Namespace were Singleton-Class is located--
> 
> <TestFixture()> Public Class TestSBHelfer
> 
>     Private helper As SBHelper 'Singleton
> 
>     ''' <summary>
>     ''' Init.
>     ''' </summary>
>     <TestFixtureSetUp()> Public Sub Init()
> 
>         helper = SBHelper.getInstance()
> 
>     End Sub
> 
>     ''' <summary>
>     ''' Testing Method doSomething()
>     ''' </summary>
>     <Test()> Public Sub singletonTest()
> 
>         helfer.doSomething()
>         Assert.IsTrue(...)
> 
>     End Sub
> 
> End Class
> 
> The problem:
> 
> When I run this test, NUnit crashes (while 'getInstance()' is 
> executed) and throws a StackOverflowException (so the test 
> itself is not completed because NUnit itself has crashed). 
> When I implement SBHelper as a 'normal' class then everything 
> works fine, so it has to do something with the Singleton.
> 
> Greetings from Hamburg
> Christian
> 



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/