标题: VS 中的unit test [打印本页] 作者: huijuan0501 时间: 2009-8-27 15:45 标题: VS 中的unit test 最近遇到些困难,利用vs中的unit tet 进行对数据库设计代码测试,这个虽然自动生成了测试框架,但里面一些还是不会,比如返回DataSet expected = DataSet actual 这了返回数据怎么来做
if (sqlParameters.Length >= 1)
{
foreach (SqlParameter sqlParameter in sqlParameters)
{
if (sqlParameter.Value == null)
{
sqlParameter.Value = string.Empty;
}
cmd.Parameters.AddWithValue(sqlParameter.ParameterName, sqlParameter.Value);
}
}
}
}
}
生成测试代码
/// <summary>
///A test for ExecuteQuery
///</summary>
[TestMethod()]
public void ExecuteQueryTest()
{
DBAccessor target = new DBAccessor(); // TODO: Initialize to an appropriate value
string commandText =@" SELECT * from UserData where [Alias]='tt'" ; // TODO: Initialize to an appropriate value
CommandType commandType = CommandType.Text; // TODO: Initialize to an appropriate value
SqlParameter[] sqlParameters = new SqlParameter[]{}; // TODO: Initialize to an appropriate value
DataSet expected = ; // TODO: Initialize to an appropriate value
DataSet actual;
actual = target.ExecuteQuery(commandText, commandType, sqlParameters);
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
/// <summary>
///A test for PrepareConnection
///</summary>
[TestMethod()]
[DeploymentItem("DBUtility.dll")]
public void PrepareConnectionTest()
{
DBAccessor_Accessor target = new DBAccessor_Accessor(); // TODO: Initialize to an appropriate value
string commandText = string.Empty; // TODO: Initialize to an appropriate value
CommandType commandType = new CommandType(); // TODO: Initialize to an appropriate value
SqlCommand cmd = null; // TODO: Initialize to an appropriate value
SqlParameter[] sqlParameters = null; // TODO: Initialize to an appropriate value
target.PrepareConnection(commandText, commandType, cmd, sqlParameters);
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
/// <summary>
///A test for DbConnectionString
///</summary>
[TestMethod()]
[DeploymentItem("DBUtility.dll")]
public void DbConnectionStringTest()
{
string actual;
actual = DBAccessor_Accessor.DbConnectionString;
Assert.Inconclusive("Verify the correctness of this test method.");
}
}
}
中的string commandText = string.Empty 等参数怎么进行设置呢?作者: huijuan0501 时间: 2009-8-28 11:07 标题: 那位会的话帮我看看这个问题哦 那位会的话帮我看看这个问题哦。先行谢过啦作者: 卡朵 时间: 2009-9-15 14:05
我也是碰到这个问题 我判断它返回的不为空就行 我也觉得很牵强 大家一起交流吧作者: huijuan0501 时间: 2009-9-16 20:42
没 ,这个问题我到现在还不明白的,事情多,我没解决这个问题