How do i do a unit test on a button click

Hi all I am trying to do unit tests on a button click event. and i cant figure it out for the life of me.
///A test for button1_Click (object, EventArgs)
        ///</summary>
        [DeploymentItem("Hotel Rate Calculator.exe")]
        [TestMethod()]
        public void button1_ClickTest()
        {
            Form1 target = new Form1();
 
            TestProject2.Hotel_Rate_Calculator_Form1Accessor accessor = new TestProject2.Hotel_Rate_Calculator_Form1Accessor(target);
 
            object sender = null; // TODO: Initialize to an appropriate value
 
            EventArgs e = null; // TODO: Initialize to an appropriate value
 
            accessor.button1_Click(sender, e);
 
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
 
    }

Open in new window

HawaiiDragonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DabasCommented:
Hello HawaiiDragon,

It does not make sense to unit test UI functionality.
It makes sense to unit test the code that the UI calls.

Hence, if your button1_Click code looks like this:

private void button1_Click()
{
 //Your code to calculate rates
}

Consider moving the calculation section to a method:

private void button1_Click()
{
      CalculateRates();
}

public void CalledMethod()
{
//Your code to calculate rates
}

Now you can call CalledMethod() from your unit test, and compare what you expect to calculate with the actual results.

Regards,

Dabas
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Miscellaneous

From novice to tech pro — start learning today.