I am trying to unit test for data being input into a textbox (txtPrice). If it is not numeric, it throws a messagebox stating that the input must be numeric. However, when I unit test, I can’t figure out why my test fires the message box twice.
THis is my (simple) unit test:
Public Sub txtBoxes_LeaveTest()
Dim target As frmEstimate_Accessor = New frmEstimate_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
sender = target.txtPrice.Text
target.txtPrice.Text = "112L"
Dim expected As String
Dim actual As String
expected = "112L"
target.txtBoxes_Leave(sender, e)
actual = target.txtPrice.Text
Assert.AreEqual(expected, actual, "txtPrice.leave event not functioning correctly")
End Sub
My understanding is that for unit testing, you declare the sender, and (in this case) set the sender to some value that will trip the message box. 112L should do this on the leave event. I then write my expected, which in this case is 112L, fire the event, and then get the actual out of the text box. I then Assert.AreEqual to ensure the expected and actual are the same.
First, is this correct? And second, why does it fire twice?
Thank you.
Use
senderonly if the Procedure name handles different control events.you can do it like this: