Re: Testing a Singleton with NUnit

"Charlie Poole" <[email protected]> Wed, 30 Jul 2008 07:10:17 -0700
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <007901c8f24e$04d75190$6401a8c0@ferrari>
Hi Christian,

Glad it's fixed. 

Thanks for putting this back on the list. When questions 
are answered off-list, others don't get the opportunity to 
learn from the answer.

Charlie 

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf 
> Of Christian Jordan
> Sent: Wednesday, July 30, 2008 1:23 AM
> To: Charlie Poole; [email protected]
> Subject: Re: [Nunit-users] Testing a Singleton with NUnit
> 
> Hi Charlie,
> 
> the "problem" is already solved. It was very amusing for me 
> (and probably for you, too :-))) to locate the error. For 
> details have a look at my discussion with Seyit!
> 
> Greetings
> Christian
> 
> -----Ursprüngliche Nachricht-----
> Von: Christian Jordan
> Gesendet: Mittwoch, 30. Juli 2008 09:29
> An: 'Seyit Caglar Abbasoglu'
> Betreff: AW: [Nunit-users] Testing a Singleton with NUnit
> 
> Hi Seyit,
> 
> thx a lot for your answer. Because there are three lines of 
> code in the getIntance() method, I was very confident about 
> the correctness of the code. In fact, the getIntance()-method 
> now looks like this:
> 
>         Public Shared Function getInstance() As SBHelper
> 
>             If SBHelper._Instance Is Nothing Then
>                 _Instance = New SBHelper()
>             End If
> 
>             Return _Instance
> 
>         End Function
> 
> If you replace "SBHelper._Instance" with 
> "SBHelper.getInstance" you would obviously get a dead 
> infinite loop :-)) and this was exactly the situation that 
> caused the OverflowException.
> 
> I if would have tried to debug the application itself before 
> trying to modifiy the test, I would found the bug on the 
> spot, but maybe it was a good "feature" that I failed on 
> this. Because now I joined this mailing list and this gives 
> me (and probably you in the future) further possibilities ;-)
> 
> Greetings
> Christian
> 
> ________________________________________
> Von: Seyit Caglar Abbasoglu
> Gesendet: Mittwoch, 30. Juli 2008 03:47
> An: Christian Jordan
> Betreff: Re: [Nunit-users] Testing a Singleton with NUnit
> 
> Hi Christian,
> 
> StackOverflowException generally means there is an infinite 
> loop in the execution. Have you tried to debug it?
> 
> -----Ursprüngliche Nachricht-----
> Von: Charlie Poole [mailto:[email protected]]
> Gesendet: Dienstag, 29. Juli 2008 20:34
> An: Christian Jordan; [email protected]
> Betreff: RE: [Nunit-users] Testing a Singleton with NUnit
> 
> 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
> > 
> 
> 
> 
> Sitz der Gesellschaft: Hamburg; Amtsgericht Hamburg HRA 
> 104052 Persönlich haftende Gesellschafterin:
> LichtBlick Verwaltungsgesellschaft mbH; Amtsgericht Hamburg HRB 97446
> Geschäftsführer: Wilfried Gillrath, Heiko von Tschischwitz
> 
> 
> --------------------------------------------------------------
> -----------
> 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=/
> _______________________________________________
> Nunit-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nunit-users
> 



-------------------------------------------------------------------------
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=/