NullReferenceException vb.net 单元测试错误
做了一些关于单元测试的作业,老实说,我只是不明白为什么会出现这个错误。
我有一个简单的方法,可以在选项卡时选择所有文本并测试是否实际选择了 textbox1。我只是不明白为什么我在 target.txtbox1_Enter(sender, 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
Doing some homework on unit testing and in all honestly i just don't get why i get this error.
i got a simple method that select all text when tab and testing if the actually textbox1 is selected. I just don't get why i'm getting a nullReferenceException at target.txtbox1_Enter(sender, e)
I'm getting really mad because this seem so easy.
any help i would appreciate it.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将是正确的做法。
This would be the correct way of doing it.