C# 在VisualStudio2010中的工具选项中使用NUnit
我已经安装了Nunit,但它没有显示在VS2010的工具菜单中。请帮助我在VS 2010中集成NUnit 您可以通过@Bili的发现将NUnit整合到VS 2010中。我更喜欢使用Resharper的TestRunner(但这需要很多钱)。NCrunch是一个免费的插件(目前),用于增强NUnit的测试。除了运行单元测试之外,它还提供代码覆盖率。我相信这是一个NuGet套餐C# 在VisualStudio2010中的工具选项中使用NUnit,c#,asp.net,unit-testing,nunit,C#,Asp.net,Unit Testing,Nunit,我已经安装了Nunit,但它没有显示在VS2010的工具菜单中。请帮助我在VS 2010中集成NUnit 您可以通过@Bili的发现将NUnit整合到VS 2010中。我更喜欢使用Resharper的TestRunner(但这需要很多钱)。NCrunch是一个免费的插件(目前),用于增强NUnit的测试。除了运行单元测试之外,它还提供代码覆盖率。我相信这是一个NuGet套餐 我编写了一些运行NUnit测试的宏。 它应该是私人的,所以我有一些假设,它不是“干净的”(我没有在它上面工作很长时间)。。
我编写了一些运行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”,然后可以将这些宏添加为工具栏按钮,例如,扩展名非常有用;它添加了用于运行NUnit测试的工具箱。您安装了什么软件包?