【问题标题】:NUnit in Visual Studio 2010 in the tools option [closed]工具选项中 Visual Studio 2010 中的 NUnit [关闭]
【发布时间】:2012-06-03 12:15:50
【问题描述】:

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

【问题讨论】:

  • 你安装了什么包?

标签: c# asp.net unit-testing nunit


【解决方案1】:

用于在 VS 2010 中集成 NUnit。Click here

【讨论】:

    【解决方案2】:

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

    http://www.ncrunch.net/

    【讨论】:

      【解决方案3】:

      我编写了一些运行 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”,然后您可以将这些宏添加为工具栏按钮,例如

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-01-22
          • 1970-01-01
          • 2012-08-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多