四、Coverlipse的安裝
1. 直接通過Eclipse即可安裝,步驟如下
In Eclipse, click Help -> Software Updates -> Find and Install.
In the dialog, select Search for new features to install, then Next.
In the next step, add a New Remote Site. Name it "Coverlipse update site", the URL is "http://coverlipse.sf.net/update/".
Press Finish. Eclipse now searches for the Coverlipse feature to install and shows that to you.
2. 配置Coverlipse以獲取代碼覆蓋
3. 一旦單擊了Run,Eclipse會運行Coverlipse并在源代碼(如圖7所示)中嵌入標(biāo)記,該標(biāo)記顯示了具有相關(guān)JUnit測試的代碼部分
4. Coverlipse生成的具有嵌入類標(biāo)記的報告
5. 正如您所見,使用Coverlipse Eclipse插件可以更快地確定代碼覆蓋率。例如,這種實時數(shù)據(jù)功能有助于在將代碼簽入CM系統(tǒng)前更好地進行測試。
五、ANT安裝,eclipse自帶,只需要配置環(huán)境變量ant_home即可。
六、創(chuàng)建一個案例
1. 創(chuàng)建一個工程testSelenium安裝下面目錄結(jié)構(gòu)
2. 錄制腳本,打開Firefox瀏覽器,進入selenium IDE菜單
3. 輸入相應(yīng)錄制的地址,點擊紅色按鈕,開始錄制
4. 將腳本轉(zhuǎn)換成junit代碼,然后將其拷貝到測試類中做為測試CASE編碼的雛形。
六、如何查看日志,這里日志分兩類:
l Junit日志,通過junit寫的斷言,和標(biāo)準(zhǔn)輸出,這些操作產(chǎn)生的日志記錄。
l Selenium日志,當(dāng)運行junit腳本時,selenium相關(guān)的腳本會產(chǎn)生回放日志,例如打開界面的url,標(biāo)準(zhǔn)輸入,輸出等信息。
雖然這兩種日志沒有交集,需要分開查看。但一般情況下我們只需要觀察Selenium日志已經(jīng)足夠用了,與其相比Junit日志更適用于編碼階段。
1. Junit日志,只需要配置腳本build-selenium.xml,如下
<project name="seleniumTest"default="junit" basedir=".">
<propertyenvironment="env" />
<conditionproperty="ia.home" value="${env.IA_HOME}">
<issetproperty="env.IA_HOME" />
</condition>
<propertyname="run.classpath" value="../class">
</property>
<propertyname="run.srcpath" value="../testSelenium">
</property>
<propertyname="test.xml" value="../xml">
</property>
<propertyname="test.report" value="../report">
</property>
<propertyname="lib.dir" value="../lib" />
<pathid="compile.path">
<filesetdir="${lib.dir}">
<includename="junit.jar" />
<includename="ant.jar" />
</fileset>
</path>
<targetname="init">
<deletedir="${run.classpath}" />
<mkdirdir="${run.classpath}" />
<deletedir="${test.report}" />
<mkdirdir="${test.report}" />
<deletedir="${test.xml}" />
<mkdirdir="${test.xml}" />
</target>
<targetname="compile" depends="init">
<javacdestdir="${run.classpath}" srcdir="${run.srcpath}" />
</target>
<targetname="junit" depends="compile">
<junitprintsummary="false">
<classpathpath="${run.classpath}">
<pathrefid="compile.path" />
</classpath>
<formattertype="xml" />
<batchtesttodir="${test.xml}">
<filesetdir="${run.classpath}">
<includename="**/Test*.class" />
<includename="**/*Test.class" />
</fileset>
</batchtest>
</junit>
<junitreporttodir="${test.xml}">
<filesetdir="${test.xml}">
<includename="TEST-*.xml" />
</fileset>
<reportformat="frames" todir="${test.report}" />
</junitreport>
</target>
</project>