Webのユニットテスト⑤ .NET
前回の続きです。
[コンパイル→アプリケーションサーバにデプロイ]を行うHudsonジョブを作ります。
プロジェクトのディレクトリ構成はこんな感じになっています。
WebAndNDbUnitSample ← ソリューション ├─WebAndNDbUnitSample ← テスト対象のプロジェクト │ ├─Web.config │ ├─Default.aspx │ └─lib │ └─NDbUnitSample.dll └─WebAndNDbUnitSampleTest ← テストプロジェクト ├─App.config ├─DefaultTest.cs ├─HtmlTableAssert.cs ├─WebTester.cs ├─NDbUnitLib │ ├─MySql.Data.dll │ ├─NDbUnit.Core.dll │ ├─NDbUnit.MySql.dll │ ├─NDbUnit.OleDb.dll │ ├─NDbUnit.OracleClient.dll │ ├─NDbUnit.SqlClient.dll │ ├─NDbUnit.SqlLite.dll │ ├─NDbUnit.SqlServerCe.dll │ └─System.Data.SQLite.DLL └─testdata └─WebAndNDbUnitSampleTest ├─userInfo.xsd └─init.xml
新規ジョブを作成
以前に作ったジョブをコピーして作ります。
ジョブの設定を変更
基本的にコピーした設定をそのまま使います。
SVNレポジトリURLやプロジェクトのルートフォルダ名は変更する必要があります。
このジョブではユニットテストを実行しないので、「JUnitテスト結果の集計」チェックは外しておきます。
default.buildなどを置く
以前に作ったdefault.build等をソリューション直下に置きます。
default.build
codeAnalysis.build
以下のファイルは、Webアプリケーション用に変更しています。
■default.build
WebアプリケーションをIISにデプロイするタスクを追加しています。
デプロイといっても、予めIISの仮想フォルダを手動で作っておいてファイルコピーしているだけです。
<?xml version="1.0" encoding="utf-8"?> <project name="UnitTestProject" default="build" basedir="."> <!-- ========================================================== --> <!-- 定義値 --> <!-- ========================================================== --> <property name="nant.settings.currentframework" value="net-3.5" /> <property name="project.name" value="WebAndNDbUnitSample"/> <property name="bin.dir" value="bin"/> <property name="report.dir" value="report"/> <property name="iis.dir" value="C:/Inetpub/wwwroot/${project.name}"/> <!-- ========================================================== --> <!-- NAntタスク実行順序 --> <!-- ========================================================== --> <target name="build"> <call target="clean" /> <call target="compile" /> <call target="deploy" /> </target> <target name="build-unitTest"> <call target="build" /> <call target="unitTest" /> </target> <target name="build-unitTest-coverage"> <call target="build" /> <nant buildfile="coverage.build" target="coverage" /> </target> <!-- ========================================================== --> <!-- ディレクトリをクリア --> <!-- ========================================================== --> <target name="clean"> <delete dir="${bin.dir}" /> <delete dir="${report.dir}" /> <mkdir dir="${bin.dir}" /> <mkdir dir="${report.dir}" /> </target> <!-- ========================================================== --> <!-- コンパイル --> <!-- ========================================================== --> <target name="compile"> <msbuild verbosity="Minimal"> <property name="Configuration" value="Release" /> <property name="OutputPath" value="..\${bin.dir}"/> </msbuild> </target> <!-- ========================================================== --> <!-- Webアプリケーションをデプロイ --> <!-- ========================================================== --> <target name="deploy"> <delete dir="${iis.dir}" /> <copy todir="${iis.dir}"> <fileset basedir="${bin.dir}/_PublishedWebsites/${project.name}"> <include name="**/*" /> </fileset> </copy> </target> <!-- ========================================================== --> <!-- ユニットテスト実行 --> <!-- ========================================================== --> <target name="unitTest"> <nunit2 failonerror="false" verbose="true"> <formatter usefile="true" type="Xml" extension=".xml" outputdir="${report.dir}"/> <test> <assemblies basedir="${bin.dir}"> <include name="*Test.dll"/> </assemblies> </test> </nunit2> </target> </project>
■codeAnalysis.build
<?xml version="1.0" encoding="utf-8"?> <project name="CodeAnalysis" default="analysis" basedir="."> <!-- ========================================================== --> <!-- 定義値 --> <!-- ========================================================== --> <property name="codeAnalysis.dir" value="codeAnalysis"/> <property name="fxcop.home" value="C:/Program Files/Microsoft FxCop 1.35"/> <property name="fxcop.project" value="WebAndNDbUnitSample.FxCop"/> <property name="fxcop.out" value="fxcop.xml"/> <!-- ========================================================== --> <!-- NAntタスク実行順序 --> <!-- ========================================================== --> <target name="analysis"> <call target="clean" /> <call target="fxcop" /> </target> <!-- ========================================================== --> <!-- ディレクトリをクリア --> <!-- ========================================================== --> <target name="clean"> <delete dir="${codeAnalysis.dir}" /> <mkdir dir="${codeAnalysis.dir}" /> </target> <!-- ========================================================== --> <!-- FxCop実行 --> <!-- ========================================================== --> <target name="fxcop"> <exec program="FxCopCmd.exe" basedir="${fxcop.home}"> <arg value="/p:${fxcop.project}" /> <arg value="/o:${codeAnalysis.dir}/${fxcop.out}" /> </exec> </target> </project>