Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Test Project Start Up Event?

My projects all use StructureMap as a container/IoC. I leverage this in things like repository patterns. In my unit test project, I've implemented test repositories when it makes sense. In order for structure map to know what concrete implementation to use, I need to initialize the container and run registration of types. I'm looking for a place to call my IoC.Initialize() in a unit test project. Outside of unit test, for example, in a web project, I can initialize my IoC container/registration from the Global.asax. I'm looking for a Unit Test equivalent of a Global.asax (e.g. static void main, a way to wire into the main start up event entry point of Unit tests). I've got around this by using a base class for all my tests, and initializing in there, so any test that is run ends up initializing the IoC container if it's not already initialize... but it's very hack-ish IMHO, so I'm looking for a cleaner way.

Any suggestions?

UPDATE/ANSWER

The following is the solution I implemented per Matthew's response.

<TestClass()>
Public Module Main

    Public Property TestContext As TestContext

    <AssemblyInitialize()>
    Public Sub Initialize(_TestContext As TestContext)

        TestContext = _TestContext
        IoC.Initialize()

    End Sub

End Module
like image 302
wakurth Avatar asked Sep 17 '13 19:09

wakurth


1 Answers

You're probably looking for the AssemblyInitializeAttribute. You can decorate a method with this in a class in your assembly and it will be run once before any tests in that assembly get run.

like image 63
Matthew Steeples Avatar answered Sep 22 '22 00:09

Matthew Steeples