1

Description of my project:

I have 2 forms: form 1 and form 2

form 1: is a logging in form that asks for a username and password if entered correctly (exists in my connected to database), form 2 shows and form 1 hides

else a messagebox shows an error message

All the unit tests out there compare actual and expected integer or string results...

so How to test the showing of/ hiding forms and showing message box??

i want to test this function:

 private void Loginbtn_Click(object sender, EventArgs e)
        {
        if (string.IsNullOrEmpty(UsernametextBox.Text))
        {
            MessageBox.Show("Please enter a Username!");
        }
        else
        {
            if (string.IsNullOrEmpty(PasswordtextBox.Text))
            {
                MessageBox.Show("Please enter a Password!");
            }
            else
            {


                if (! Program.myController.Form1LoginButtonPressed(UsernametextBox.Text, PasswordtextBox.Text))
                {
                    MessageBox.Show("error");
                }

                this.UsernametextBox.Clear();
                this.PasswordtextBox.Clear();

            }

        }
    }

thanks in advance

CodeX
  • 135
  • 2
  • 13
  • Are you following some design pattern? How you have your current tests? And how is your production code layout? – Alejandro May 08 '15 at 19:56
  • 3
    _"All the unit tests out there compare actual and expected integer or string results"_ - then you need to find proper tutorials with more explanation. Abstract the behavior that your form invokes: don't let the form use `MessageBox.Show()` or `Form2.Show()` directly, but put that logic in a class and mock that class. You also don't want forms to show each other, especially not if you want that to be testable, but use some kind of MVC or MVVM pattern where you have a controller that decides which form to show after which action occurs. – CodeCaster May 08 '15 at 20:00
  • following MVC design pattern .. just a simple project for now.. tested by entering some test data by myself (smoke test).. i have form1.cs, form2.cs , DBhelper and DBmanager with the connection string, controller... check the edits plz – CodeX May 08 '15 at 20:04
  • 1
    There's a difference between *unit testing* and *user interface testing* or *UI testing*. Don't confuse the two. – Ken White May 08 '15 at 20:41
  • possible duplicate of [Messagebox and Unit testing](http://stackoverflow.com/questions/8560865/messagebox-and-unit-testing) – forsvarir May 13 '15 at 13:12

0 Answers0