Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7458999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:55:41+00:00 2026-05-29T13:55:41+00:00

I am trying to unit test for data being input into a textbox (txtPrice).

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:55:41+00:00Added an answer on May 29, 2026 at 1:55 pm

    Use sender only if the Procedure name handles different control events.

    you can do it like this:

    Private Sub txtPrice_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPrice.Leave
        If Not IsNumeric(txtPrice.Text) Then
            MsgBox("txtPrice is not numeric!", MsgBoxStyle.Critical, "Error")
            txtPrice.SelectAll()
            txtPrice.Focus()
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to unit test a thin data access layer that I've written.
I'm trying to Unit Test a class that has many internal functions. These obviously
I'm trying to unit test a page in my ASP.NET MVC application that, when
I am trying to unit test a controller action that uses UpdateModel but I
I'm trying to unit test a private method that I have attached to my
In trying to setup a unit test for inserting an item into an SQL
I'm trying to test the Data values that are returned from an ASP.NET MVC3
When trying to unit-test a methode I run into a problem. The task of
I'm trying to unit test a few .NET classes that (for good design reasons)
I'm trying to unit test my routes using the MvcContrib.TestHelper ShouldMapTo <TController> () extension

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.