1

我已经安装了 Nunit,但它没有显示在 VS 2010 的工具菜单中。请帮助我

4

4 回答 4

0

用于在 VS 2010 中集成 NUnit。单击此处

于 2012-06-03T12:22:15.433 回答
0

您可以通过@Bili 找到的内容将 NUnit 集成到 VS 2010 中。我更喜欢使用 Resharper 的测试运行器(但这要花很多钱)。NCrunch 是一个免费插件(目前),它增强了 NUnit 的测试。除了运行单元测试之外,它还提供代码覆盖率。我相信这是一个 NuGet 包。

http://www.ncrunch.net/

于 2012-06-03T13:06:40.267 回答
0

我写了一些运行 NUnit 测试的宏。它应该是私有的,所以我有一些假设并且它不是那么“干净”(我没有长时间工作)......但是如果你想关注它们,你可以获得一种非常舒适的“整合”方式VS 中的测试

假设:

  • 您必须在 PATH 环境变量中有 NUnit bin 文件夹
  • 测试项目“someName”将在“someName.Test”项目中(用于集成测试 - “someName.integration”)

如果您认为它可能会使您的工作变得轻松,那么代码就在这里:

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports EnvDTE90a
    Imports EnvDTE100
    Imports System.Diagnostics
    Imports System.Collections.Generic
    Imports System.IO



    Public Module NUnitExtensions
        Sub AttachToNUnit()
            Dim attached As Boolean = False
            Dim proc As EnvDTE.Process

            For Each proc In DTE.Debugger.LocalProcesses
                If (Right(proc.Name.ToLower(), 9) = "nunit.exe") Then
                    proc.Attach()
                    attached = True
                    Exit For
                End If
            Next

        End Sub

        Private Sub RunNunitFile(ByRef dll)
            Dim args = """" & dll & """" & " /run"
            System.Diagnostics.Process.Start("nunit.exe", args)
        End Sub

        Private Function GetSolutionFiles(ByRef filePattern) As String()
            Dim solutionDir = System.IO.Path.GetDirectoryName(DTE.Solution.FullName)
            Dim nunitFiles = System.IO.Directory.GetFiles(solutionDir, filePattern, IO.SearchOption.AllDirectories)
            Return nunitFiles
        End Function

        Private Function GetDllCompilationAttributes(ByRef dllFullPath) As Boolean()
            Dim ActiveDoc As Document = DTE.ActiveDocument
            Dim Proj As Project = ActiveDoc.ProjectItem.ContainingProject
            Dim config As Configuration = Proj.ConfigurationManager.ActiveConfiguration
            Dim result(2) As Boolean
            result(0) = False
            result(1) = False
            Dim parts = Split(dllFullPath, "\")
            For Each part As String In parts
                If part.ToLower() = "obj" Then
                    result(1) = True
                End If
                If part.ToLower() = config.ConfigurationName.ToLower() Then
                    result(0) = True
                End If
            Next
            Return result
        End Function

        Sub RunNUnit()

            Dim nunitUnitTestFiles = GetSolutionFiles("*test.dll")
            Dim nunitIntegrationTestFiles = GetSolutionFiles("*integration.dll")

            Dim unitTestsAndIntegrationTestFiles As New List(Of String)

            unitTestsAndIntegrationTestFiles.AddRange(nunitUnitTestFiles)
            unitTestsAndIntegrationTestFiles.AddRange(nunitIntegrationTestFiles)

            For Each dll As String In unitTestsAndIntegrationTestFiles
                Dim dllAttributes = GetDllCompilationAttributes(dll)
                Dim debug = dllAttributes(0)
                Dim obj = dllAttributes(1)

                If debug AndAlso Not obj Then
                    RunNunitFile(dll)
                End If

            Next

        End Sub

        Sub RunCurrentProjectNUnit()

            Dim ActiveDoc As Document = DTE.ActiveDocument
            Dim Proj As Project = ActiveDoc.ProjectItem.ContainingProject
            Dim config As Configuration = Proj.ConfigurationManager.ActiveConfiguration

            Dim projectFileName = Proj.FullName
            Dim projectPath = Path.GetDirectoryName(projectFileName)
            Dim dllName = Proj.Name

            If (Not projectPath.ToLower().EndsWith(".test")) Then
                projectPath += ".Test"
                dllName += ".Test"
            End If

            Dim testDllPath = String.Format("{0}\bin\{1}\{2}.dll", projectPath, config.ConfigurationName, dllName)

            RunNunitFile(testDllPath)
        End Sub
    End Module

确保如果将其添加到宏窗口 (Alt+F8),则必须将代码文件命名为“NUnitExtensions”,然后您可以将这些宏添加为工具栏按钮,例如

于 2012-06-03T13:37:08.200 回答
0

Visual NUnit扩展非常有用;它添加了一个用于运行 NUnit 测试的工具箱。

于 2012-06-03T14:28:04.017 回答