|
请大家帮帮忙
要测试的方法如下:
public int DeleteWeek(Week wek)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["weekyConnectionString"].ConnectionString);
SqlCommand delcmd = new SqlCommand("delete from Week where We_id=@We_id", conn);
delcmd.Parameters.Add(new SqlParameter("@We_id", wek.We_id));
conn.Open();
int i = delcmd.ExecuteNonQuery();
conn.Close();
return i;
}
测试代码如下:
[TestFixture]
public class WeekTest
{
//private Week wk;
private WeeksDB wkdb = new WeeksDB();
[Test]
public void DeleteTest()
{
//wk = new Week("1232", "1", "1", "1", "1", "1", "1", "1");
int a = wkdb.DeleteWeek(new Week("1232", "1", "1", "1", "1", "1", "1", "1"));
Assert.AreEqual(0,a);
}
}
在NUnit按RUN时出现问题如下:
ClassLibrary1.WeekTest.DeleteTest : System.NullReferenceException : 未将对象引用设置到对象的实例。
在 WeeksDB.DeleteWeek(Week wek) 位置 C:\Documents and Settings\Franky\My Documents\Visual Studio 2005\Projects\WebSite4\ClassLibrary1\WeeksDB.cs:行号 157
在 ClassLibrary1.WeekTest.DeleteTest() 位置 C:\Documents and Settings\Franky\My Documents\Visual Studio 2005\Projects\WebSite4\ClassLibrary1\WeekTest.cs:行号 17 |
|