VisualStudio2005ProfessionalEditionのマクロでコードカバレッジ
VisualStudio2005 ProfessionalEditionにはテスト機能はついていませんので、コードカバレッジテストをするのは大変です。
そこで、VisualStudioのマクロ機能を利用して現在のデバック行を出力するものを作りました。
あとはExcelに取り込んでVBAで動かしてやればいい感じでコードカバレッジテストが行えます。
といってもまだまだ出来はよくないですけどね。
Option Strict Off Option Explicit Off Imports System Imports EnvDTE Imports EnvDTE80 Imports System.Diagnostics Public Module Coverage '------------------------------------------------------------------------- ' 関数: 出力ウインドウ取得 '------------------------------------------------------------------------- Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show As Boolean = True) As OutputWindowPane Dim window As Window Dim outputWindow As OutputWindow Dim outputWindowPane As OutputWindowPane window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput) If show Then window.Visible = True outputWindow = window.Object Try outputWindowPane = outputWindow.OutputWindowPanes.Item(Name) Catch e As System.Exception outputWindowPane = outputWindow.OutputWindowPanes.Add(Name) End Try outputWindowPane.Activate() Return outputWindowPane End Function '------------------------------------------------------------------------- ' 関数: ステップオーパーカバレッジ '------------------------------------------------------------------------- Sub CoverOver() Dim outputWinPane As EnvDTE.OutputWindowPane Dim textSelection As EnvDTE.TextSelection outputWinPane = GetOutputWindowPane("Debugger") textSelection = DTE.ActiveDocument.Selection DTE.Debugger.StepOver() If (Not DTE.Debugger.CurrentStackFrame Is Nothing) Then outputWinPane.OutputString(DTE.Debugger.CurrentStackFrame.FunctionName & "," & textSelection.ActivePoint.Line & vbCrLf) End If End Sub '------------------------------------------------------------------------- ' 関数: ステップインカバレッジ '------------------------------------------------------------------------- Sub CoverIn() Dim outputWinPane As EnvDTE.OutputWindowPane Dim textSelection As EnvDTE.TextSelection outputWinPane = GetOutputWindowPane("Debugger") textSelection = DTE.ActiveDocument.Selection DTE.Debugger.StepInto() If (Not DTE.Debugger.CurrentStackFrame Is Nothing) Then outputWinPane.OutputString(DTE.Debugger.CurrentStackFrame.FunctionName & "," & textSelection.ActivePoint.Line & vbCrLf) End If End Sub '------------------------------------------------------------------------- ' 関数: ステップアウトカバレッジ '------------------------------------------------------------------------- Sub CoverOut() Dim outputWinPane As EnvDTE.OutputWindowPane Dim textSelection As EnvDTE.TextSelection outputWinPane = GetOutputWindowPane("Debugger") textSelection = DTE.ActiveDocument.Selection DTE.Debugger.StepOut() If (Not DTE.Debugger.CurrentStackFrame Is Nothing) Then outputWinPane.OutputString(DTE.Debugger.CurrentStackFrame.FunctionName & "," & textSelection.ActivePoint.Line & vbCrLf) End If End Sub '------------------------------------------------------------------------- ' 関数: 終了するまでステップインカバレッジ '------------------------------------------------------------------------- Sub CoverContinueInto() Dim outputWinPane As EnvDTE.OutputWindowPane Dim textSelection As EnvDTE.TextSelection outputWinPane = GetOutputWindowPane("Debugger") outputWinPane.Clear() While DTE.Debugger.CurrentMode <> dbgDebugMode.dbgDesignMode textSelection = DTE.ActiveDocument.Selection DTE.Debugger.StepInto() If (Not DTE.Debugger.CurrentStackFrame Is Nothing) Then outputWinPane.OutputString(DTE.Debugger.CurrentStackFrame.FunctionName & "," & textSelection.ActivePoint.Line & vbCrLf) End If End While End Sub '------------------------------------------------------------------------- ' 関数: 終了するまでステップインカバレッジ(同一NameSpace内) '------------------------------------------------------------------------- Sub CoverContinueIntoOne() Dim outputWinPane As EnvDTE.OutputWindowPane Dim textSelection As EnvDTE.TextSelection Dim strFunctionName As String = "" outputWinPane = GetOutputWindowPane("Debugger") outputWinPane.Clear() Try While DTE.Debugger.CurrentMode <> dbgDebugMode.dbgDesignMode textSelection = DTE.ActiveDocument.Selection strFunctionName = DTE.Debugger.CurrentStackFrame.FunctionName DTE.Debugger.StepInto() If (strFunctionName.Split(".")(0) <> DTE.Debugger.CurrentStackFrame.FunctionName.Split(".")(0)) Then DTE.Debugger.StepOut() End If If (Not DTE.Debugger.CurrentStackFrame Is Nothing) Then outputWinPane.OutputString(DTE.Debugger.CurrentStackFrame.FunctionName & "," & textSelection.ActivePoint.Line & vbCrLf) End If End While Catch ex As Exception End Try End Sub End Module