做單元測試的一些作業,並在所有老實說,我只是不明白爲什麼我得到這個錯誤。NullReferenceException vb.net單元測試錯誤
我有一個簡單的方法,選擇所有文本時選項卡和測試,如果實際textbox1被選中。我只是不明白爲什麼我在target.txtbox1_Enter(發送者,e)得到nullReferenceException
我越來越生氣,因爲這看起來很容易。
任何幫助,我將不勝感激。
Private Sub txtbox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtbox1.enter
Dim txtBox As TextBox
txtBox = CType(sender, TextBox)
txtBox.SelectAll()
End Sub
<TestMethod(), DeploymentItem("frmtesting.exe")>
Public Sub txtCustomer_EnterTest()
Dim target As frmtesting_Accessor = New frmtesting_Accessor ' TODO: Initialize to an appropriate value
Dim sender As Object = Nothing ' TODO: Initialize to an appropriate value
Dim e As EventArgs = Nothing ' TODO: Initialize to an appropriate value
Dim expected As String
Dim actual As String
target.txtbox1.Text = "bob"
target.txtbox1.SelectAll()
expected = "bob"
target.txtbox1_Enter(sender, e)
actual = target.txtbox1.SelectedText
Assert.AreEqual(expected, actual, "not equal")
End Sub
'Sender'爲空。 'Dim sender as Object = Nothing'然後你將它傳遞給'txtbox1_Enter'。 –
可能重複[什麼是.NET中的NullReferenceException?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net) –