您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
不僅僅只有JUnit
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2013/3/25 15:00:32 ] 推薦標簽:

二、IValidator
        當初看到這個開源的測試框架時,不由又喜又悔。喜的是:IValidator居然跟我寫的TAF(Testing Automation Framework)有幾分相象,真是英雄所見略同啊,而且它的版本已經(jīng)是2.1了,看來這一套還是可行的;悔的是:為何當初沒發(fā)現(xiàn),也省的我摸黑,沒有一個參考。
        好了,賣足了關(guān)子,給大家介紹一下這IValidator的樣子。
IValidator的功能特性有:
1、測試用例是基于XML的。
2、適用于復(fù)合測試的場景。
3、集成Eclipse的開發(fā)環(huán)境。

IValidator使用XML來描述測試用例,如:下面是一個例子:
<?xml version="1.0" encoding="UTF-8"?>
<descriptor-repository xmlns="http://www.ivalidator.org/schemas/xml-repository">
<test name="Sleeping Suite">
<setups>
<setup alias="sleep"/>
</setups>
<flow>
<test alias="sleep"/>
<test alias="sleep"/>
<test alias="sleep"/>
</flow>
<checkups>
<checkup alias="sleep"/>
</checkups>
<teardowns>
<teardown alias="sleep"/>
</teardowns>
</test>

<unitlib>
<unit name="sleep">
<description>
Sleeps for the provided count of seconds.
</description>
<parameters>
<parameter name="seconds" value="5"/>
</parameters>
<instance class="org.ivalidator.sample.base.SleepTest" method="sleep"/>
</unit>
</unitlib>
</descriptor-repository>

        如果你仔細看的話,你其實已經(jīng)明白每個xml節(jié)點里的含義了--每個節(jié)點會調(diào)用某些Java類的方法來完成一些功能,把這些功能串其來能完成一個完整的測試用例了。注意alias的值是在unitlib節(jié)點下定義的,以下是代碼SleepTest 類。
public class SleepTest implements Unit
{
private UnitContext context;
/**
* @inheritDoc
*/
public void setContext(UnitContext _context)
{
this.context = _context;
}

/**
* Sleeps for <code>seconds</code> milliseconds. If <code>seconds</code>
* is not provided, 1 second is the default.
*/
public void sleep()
{
Parameter paramSeconds = this.context.getParameter("seconds");
int seconds = paramSeconds != null ? paramSeconds.asInt() : 1;

try
{
for(int i = seconds; i > 0; i--)
{
this.context.getLogger().info("Seconds to go: " + i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
return;
}
}

}

        也是說,你只要實現(xiàn)Unit接口,IValidator框架會將xml中的數(shù)據(jù)傳入UnitContext 中(通過setContext方法),IValidator框架會在當前測試用例的整個生命周期中維護UnitContext,
        而測試代碼也可以將測試過程中的中間數(shù)據(jù)放回到UnitContext中,也是說,測試代碼于測試框架之間交互是通過UnitContext來完成的。

        客觀來將IValidator是JUnit的一種補充,但不能取代JUnit。
        好處不說了,留給讀者去體會吧,個人認為的缺點有:
1、框架本身不提供斷言功能,僅僅提供測試步驟的調(diào)度和維護測試代碼的上下 文,所有的實現(xiàn)都是在實現(xiàn)類里面,雖然可以通過修改輸入?yún)?shù)來改變測試輸入條 件,但顯然仍過于蒼白。
2、報告不夠全面,從報告中仍不能
3、減輕開發(fā)人員的多少工作量有限。

        不過,我覺得,開發(fā)人員借助IValidator,可以將測試代碼寫的靈活一些,測試數(shù)據(jù)不要寫死在代碼里面,這樣,測試人員可以修改測試數(shù)據(jù)來校驗代碼的質(zhì)量,這在不少的場景下很有意義。

上一頁12下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd