再次运行测试,看见绿条,测试通过。不过这里只是一个假实现并没有真正实现查找功能,我们需要对测试进行修改使之更加完善。
IE ie = new IE("http://localhost:1781/Default.aspx");
ie.TextField(Find.ById("tb_customerID")).TypeText("ALFKI");
ie.Button(Find.ById("btn_find_customer")).Click();
Assert.That(ie.ContainsText("ALFKI"), Is.True);
Assert.That(ie.ContainsText("Alfreds Futterkiste"), Is.True);
ie.TextField(Find.ById("tb_customerID")).TypeText("AROUT");
ie.Button(Find.ById("btn_find_customer")).Click();
Assert.That(ie.ContainsText("AROUT"), Is.True);
Assert.That(ie.ContainsText("Around the Horn"), Is.True);
ie.Close();
运行测试,又会出现红条了,测试失败。现在要考虑实现一个真正的在数据库中的查找功能,怎么开始做呢?当然还是由测试开始,有了上面的基础,现在写的测试跨库可以稍微大点:
[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));