【CFCUnit】:CFC用のUnitTestフレームワーク
■環境構築
1.最新バージョンのcfcUnitをダウンロード(2006/12/14
時点で1.1.0 RC1)
http://www.cfcunit.org/cfcunit/index.cfm?event=Download
2.ダウンロードしたzipファイルを解凍
3.解凍したフォルダ内の
・org
・cfcunit
の2つのフォルダをwebルートにコピー
4.http://localhost/cfcunit/index.cfmにアクセス
5."Enter test to
run:"という見出しの付いたフォームが表示されるので、"Test
Class:"の入力エリアに
org.cfcunit.tests.AllTests
と入力して"Run Test"ボタンを押す
6.Text Runner、HTML
Runnerそれぞれでテストをしてエラーが無かったらインストール完了
■クラス作成
1.『Sample1』(CFML)プロジェクトを作成し、そのフォルダの直下に以下のコードのCalculator.cfcを作成する。
※プロジェクトの出力先は『C:\Inetpub\wwwroot\』に指定すること。
<cfcomponent name="Calculator" output="false" hint="This is a basic
calculator">
<cffunction name="add" returntype="numeric" access="public"
output="false" hint="Adds op2 to op1.">
<cfargument name="op1" type="numeric" required="true" hint="Left
operand."/>
<cfargument name="op2" type="numeric" required="true" hint="Right
operand"/>
<cfreturn (arguments.op1 + arguments.op2)/>
</cffunction>
<cffunction name="subtract" returntype="numeric" access="public"
output="false" hint="Subtracts op2 from op1.">
<cfargument name="op1" type="numeric" required="true" hint="Left
operand."/>
<cfargument name="op2" type="numeric" required="true" hint="Right
operand."/>
<cfreturn (arguments.op1 - arguments.op2)/>
</cffunction>
<cffunction name="multiply" returntype="numeric" access="public"
output="false" hint="Multiplies op1 by op2.">
<cfargument name="op1" type="numeric" required="true" hint="Left
operand."/>
<cfargument name="op2" type="numeric" required="true" hint="Right
operand."/>
<cfreturn (arguments.op1 * arguments.op2)/>
</cffunction>
<cffunction name="divide" returntype="numeric" access="public"
output="false" hint="Divides numerator by divisor.">
<cfargument name="numerator" type="numeric" required="true"
hint=""/>
<cfargument name="divisor" type="numeric" required="true"
hint=""/>
<cfreturn (arguments.numerator / arguments.divisor)/>
</cffunction>
</cfcomponent>
2.
『Sample1』プロジェクトのフォルダの直下に以下のコードのCalculatorTest.cfcを作成する。
<cfcomponent name="CalculatorTest" extends="org.cfcunit.framework.TestCase"
output="false" hint="This tests the Calculator component.">
<cffunction name="testAdd" returntype="void" access="public"
output="false">
</cffunction>
<cffunction name="testSubtract" returntype="void" access="public"
output="false">
</cffunction>
<cffunction name="testMultiply" returntype="void" access="public"
output="false">
</cffunction>
<cffunction name="testDivide" returntype="void" access="public"
output="false">
</cffunction>
</cfcomponent>
■テスト実行
1. http://localhost/cfcunit/index.cfmにアクセス
2.
テストクラスにSample1.CalculatorTestと入力して、ボタンを押下する。
3. 正常に結果が返却されることを確認する。
以上
最終更新:2006年12月27日 11:37