您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源功能測(cè)試工具 > Watir
用Web自動(dòng)化測(cè)試框架WatiN進(jìn)行TDD
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/3/12 16:10:52 ] 推薦標(biāo)簽:

運(yùn)行測(cè)試,又會(huì)出現(xiàn)紅條了,測(cè)試失敗,F(xiàn)在要考慮實(shí)現(xiàn)一個(gè)真正的在數(shù)據(jù)庫(kù)中的查找功能,怎么開始做呢?當(dāng)然還是由測(cè)試開始,有了上面的基礎(chǔ),現(xiàn)在寫的測(cè)試跨庫(kù)可以稍微大點(diǎn):

[TestFixture]

public class CustomerDAOTests

{

[Test]

public void ShouldFoundCustomerByID()

{

string id = "ALFKI";

string comName = "Alfreds Futterkiste";

CustomerDAO customerDAO = new CustomerDAO();

Customer found = customerDAO.FindCustomerByID(id);

Assert.That(found, Is.Not.Null);

Assert.That(found.CustomerID, Is.EqualTo(id));

Assert.That(found.CompanyName, Is.EqualTo(comName));

id = "AROUT";

comName = "Around the Horn";

found = customerDAO.FindCustomerByID(id);

Assert.That(found, Is.Not.Null);

Assert.That(found.CustomerID, Is.EqualTo(id));

Assert.That(found.CompanyName, Is.EqualTo(comName));

}

}

這段代碼不能編譯,因?yàn)椴]有CustomerDAO這個(gè)類,所以得新增該類以及FindCustomerByID方法,而且上面的測(cè)試中已經(jīng)包括了兩個(gè)測(cè)試場(chǎng)景,現(xiàn)在可以直接寫實(shí)現(xiàn):

public class CustomerDAO

{

public Customer FindCustomerByID(string id)

{

using (NorthwindDataContext ctx = new NorthwindDataContext())

{

IQueryable customers = ctx.Customers.Where(c => c.CustomerID == id);

if (customers.Count() > 0)

return customers.Single();

else

return null;

}

}

}

運(yùn)行一下該測(cè)試,通過!然后再將aspx.cs里面的代碼進(jìn)行改動(dòng)使Web頁面的測(cè)試通過

void btn_find_customer_Click(object sender, EventArgs e)

{

string id = tb_customerID.Text;

Customer c = customerDAO.FindCustomerByID(id);

if (c == null)

return;

lbl_customerID.Text = c.CustomerID;

lbl_companyName.Text = c.CompanyName;

pnl_customerInfo.Visible = true;

}

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