Testing a Singleton with NUnit

"Christian Jordan" <[email protected]> Tue, 29 Jul 2008 20:28:34 +0200
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <[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.

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