我正在尝试使用单元测试向导进行单元测试,但我总是得到:
测试方法 TestProject9.Log_InsertMasterTest 抛出异常:
System.NullReferenceException:对象引用未设置为对象的实例。
我的test.cs:
[TestMethod()]
[DeploymentItem("Engine.dll")]
public void Log_InsertMasterTest()
{
SkinnedRepairSearch_Accessor target = new SkinnedRepairSearch_Accessor(); // TODO: Initialize to an appropriate value
int RepairMasterID = 0; // TODO: Initialize to an appropriate value
int RepairMasterIDOld = 0; // TODO: Initialize to an appropriate value
int id = 0; // TODO: Initialize to an appropriate value
string Text = string.Empty; // TODO: Initialize to an appropriate value
target.Log_InsertMaster(RepairMasterID, RepairMasterIDOld, id, Text);
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
Log_InsertMaster 方法:
protected void Log_InsertMaster(int RepairMasterID, int RepairMasterIDOld, int id, string Text)
{
SqlConnection myConnection = new SqlConnection(Globals.DatabaseConnectionString);
SqlCommand myCommand = new SqlCommand("dbo.Repair_LogInsertMaster", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@RepairMasterID", SqlDbType.Int).Value = RepairMasterID;
myCommand.Parameters.Add("@RepairMasterIDold", SqlDbType.Int).Value = RepairMasterIDOld;
myCommand.Parameters.Add("@DateTime", SqlDbType.DateTime).Value = System.DateTime.Now;
myCommand.Parameters.Add("@RepairID", SqlDbType.Int).Value = id;
myCommand.Parameters.Add("@UserSignature", SqlDbType.NVarChar, 200).Value = AdminUser.Signature;
myCommand.Parameters.Add("@Text", SqlDbType.NVarChar, 200).Value = Text;
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
如何不出现此错误?以及如何使用 Unint 测试向导?
异常行:
SkinnedRepairSearch_Accessor target = new SkinnedRepairSearch_Accessor(); // TODO: Initialize to an appropriate value
我尝试了其他公共方法:
[TestMethod()]
public void EmptyTextBoxesTest()
{
SkinnedRepair target = new SkinnedRepair(); // TODO: Initialize to an appropriate value
Control parent = null; // TODO: Initialize to an appropriate value
target.EmptyTextBoxes(parent);
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
同样的错误