#ls2

Visual Studio 設定

  • NUnit にパスが通っていること。
  • Visual C# 2010 Express だと、外部ツールとビルドイベントとでマクロの値が違うのはなんでなんだぜ。(--#) | | 外部ツール | ビルドイベント | | --- | --- | --- | | TargetPath | obj\Release\$(TargetName)$(TargetExt) | bin\Release\$(TargetName)$(TargetExt) | | TargetDir | obj\Release\ | bin\Release\ | | TargetName | (ターゲット名) | (ターゲット名) | | TargetExt | .exe または .dll | .exe または .dll | | TargetFileName | - | $(TargetName)$(TargetExt) | | BinDir | bin\Release\ | - | | OutDir | - | bin\Release\ |

随時実行

  • 「ツール - 外部ツール」に追加する。 | タイトル | NUnit(&U) | | --- | --- | | コマンド | nunit-console-x86.exe | | 引数 | "$(BinDir)$(TargetName)$(TargetExt)" | | 初期ディレクトリ | "$(BinDir)" | | 出力ウィンドウを使用 | チェックする | | 起動時に引数を入力 | チェックしない | | Unicodeで出力を処理する | チェックしない |
  • 単体テストのコードを含むプロジェクトを選択している状態で実行する。

ビルド時に自動実行

  • 単体テストのコードを含むプロジェクトのプロパティを開き、「ビルドイベント」で設定する。 | ビルド後に実行するコマンドライン
    (NUnit 2.x) | if "$(ConfigurationName)" == "Release" (
      cd /d "$(TargetDir)"
      if "$(PlatformName)" == "x64" (
        nunit-console.exe "$(TargetPath)"
      ) else if "$(PlatformName)" == "x86" (
        nunit-console-x86.exe "$(TargetPath)"
      ) else (
        echo "NUnit skipped on platform: $(PlatformName)"
      )
    ) | | --- | --- | | ビルド後に実行するコマンドライン
    (NUnit 3.x) | if "$(ConfigurationName)" == "Release" (
      cd /d "$(TargetDir)"
      nunit3-console.exe "$(TargetPath)" --result="$(TargetName).xml"
    ) | | ビルド後に実行するコマンドライン
    (NUnit 3.x + ReportUnit) | if "$(ConfigurationName)" == "Release" (
      NUnit_Report "$(TargetDir)" "$(TargetPath)" "$(TargetName)"
    ) | | ビルド後イベントの実行 | ビルドがプロジェクト出力を更新したとき |

NUnit_Report.bat

set TargetDir=%1
set TargetPath=%2
set TargetName=%3
cd /d "%TargetDir%"
nunit3-console.exe "%TargetPath%" --result="%TargetName%.xml"
set ErrorCount=%ERRORLEVEL%
ReportUnit "%TargetName%.xml"
exit /b %ErrorCount%

Link

おまけ

  • マクロ値確認に使ったバッチファイル
    @echo off
    echo %cd%
    :loop
    echo %0
    shift
    if not '%0' == '' goto loop