Freigeben über


NUnit & VS Integration Macro

I'm always using a simple macro to configure test projects in VS, here is the macro updated to NUnit 2.2

Imports System

Imports EnvDTE

Imports System.Diagnostics

Imports VSLangProj

#Region "Path to NUnit"

Public Module NUnitConstants

    Public Const BASE_PATH As String = "c:\Program Files\NUnit 2.2\bin\"

    Public Const NUNIT_FX As String = BASE_PATH & "nunit.framework.dll"

    Public Const NUNITGUI_RUNNER As String = BASE_PATH & "nunit-gui.exe"

End Module

#End Region

Public Module TestProjectConfigurator

    Dim currentProject As VSProject

#Region "Private"

    Private Sub addReference(ByVal referencePath As String)

        currentProject.References.Add(referencePath)

    End Sub

    Private Sub setDebugProperties(ByVal runnerPath As String)

        Dim assemblyName As EnvDTE.Property = CType(currentProject.Project.Properties.Item("AssemblyName"), EnvDTE.Property)

        Dim configProps As Properties = currentProject.Project.ConfigurationManager.ActiveConfiguration.Properties

        With configProps

            .Item("StartAction").Value = prjStartAction.prjStartActionProgram

            .Item("StartProgram").Value = runnerPath

            .Item("StartArguments").Value = assemblyName.Value + ".dll"

        End With

    End Sub

    Private Sub setBuildEvents()

        Dim configProps As Properties = currentProject.Project.Properties

        Dim appConfigCmd = "copy ""$(ProjectDir)App.config"" ""$(TargetDir)$(TargetFileName).config"""

        With configProps

            .Item("PreBuildEvent").Value = appConfigCmd

   End With

    End Sub

    Private Sub configureProject()

        addReference(NUNIT_FX)

        setDebugProperties(NUNITGUI_RUNNER)

        setBuildEvents()

    End Sub

#End Region

    Public Sub Run()

        currentProject = DTE.ActiveSolutionProjects(0).Object

        configureProject()

    End Sub

    Public Sub ResetConfig(ByVal nada As Object)

        currentProject = DTE.ActiveSolutionProjects(0).Object

    End Sub

End Module

Comments