51Testing软件测试论坛
标题:
新手的疑问:如何在PETSHOP 4.0模式下进行单元测试
[打印本页]
作者:
evan007
时间:
2007-11-9 11:43
标题:
新手的疑问:如何在PETSHOP 4.0模式下进行单元测试
如题,我做了一个基于PETSHOP 4.0模式的项目,现在做单元测试的时候遇到了个问题:如果我要对BLL层进行单元测试的话,我应该怎么进行测试呢?
测试代码如下: BLL层:
public System.Collections.Generic.IList<Water.Model.Company> GetCompanyByUserName(string userName)
{
IList<Company> companies = DataAccess.CreateCompanyDal().GetCompanyByUserName(userName);
foreach (Company company in companies)
{
company.ParentCompanyName = GetCompanyByCompanyId(company.ParentCompanyId).CompanyName;
}
return companies;
}
SQL层代码为:
public IList<Company> GetCompanyByUserName(string userName)
{
IList<Company> companys = new List<Company>();
SqlParameter parm = new SqlParameter("@userName", userName);
using (SqlDataReader rdr = (SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SELECT_COMPANY_BY_USERNAME, parm)))
{
while (rdr.Read())
{
Company company = new Company();
company.CompanyId = (int)rdr["CompanyId"];
company.CompanyName = rdr["CompanyName"].ToString();
company.Level = (int)rdr["Level"];
company.ParentCompanyId = (int)rdr["ParentCompanyId"];
companys.Add(company);
}
}
return companys;
}
生成的测试代码模板为:
/// <summary>
///GetCompanyByUserName (string) 的测试
///</summary>
[TestMethod()]
public void GetCompanyByUserNameTest ( )
{
CompanyBLL target = new CompanyBLL();
string userName = null; // TODO: 初始化为适当的值
System.Collections.Generic.IList<Water.Model.Company> expected = null;
System.Collections.Generic.IList<Water.Model.Company> actual;
actual = target.GetCompanyByUserName(userName);
Assert.AreEqual(expected, actual, "Water.BLL.CompanyBLL.GetCompanyByUserName 未返回所需的值。");
Assert.Inconclusive("验证此测试方法的正确性。");
}
对于 string userName = null; // TODO: 初始化为适当的值
System.Collections.Generic.IList<Water.Model.Company> expected = null;
这两行我应该怎么设置,请大家指教,谢谢~~
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2