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

運(yùn)行測試,又會出現(xiàn)紅條了,測試失敗。現(xiàn)在要考慮實(shí)現(xiàn)一個真正的在數(shù)據(jù)庫中的查找功能,怎么開始做呢?當(dāng)然還是由測試開始,有了上面的基礎(chǔ),現(xiàn)在寫的測試跨庫可以稍微大點(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這個類,所以得新增該類以及FindCustomerByID方法,而且上面的測試中已經(jī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)行一下該測試,通過!然后再將aspx.cs里面的代碼進(jìn)行改動使Web頁面的測試通過

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