Re: Testing a Singleton with NUnit

"Seyit Caglar Abbasoglu" <[email protected]> Wed, 30 Jul 2008 13:16:50 +0300
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <[email protected]>
You're welcome

May I also suggest you to subscribe TestDrivenDevelopment group in Yahoo
Groups.

By the way It still confuses me when my reply does not go to the group but
directly to sender in SourceForge. I should be more careful next time. It
seems our discussion was accidentially private :)

2008/7/30 Christian Jordan <[email protected]>

> 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 [mailto:[email protected]]
> 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?
> 2008/7/29 Christian Jordan <[email protected]>
> 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.
>
>
> 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