title: How do you know whether to automate testing or use manual?
body: <p>I've made a login screen and menu for a Doctors management system. User logs in and is sent to main menu, depending on role type they have different controls on each sub menu. </p>
  
  <p>It all works well and now its time to test.</p>
  
  <p>I've never done automated testing - unit, integration or end to end. </p>
  
  <p>As I understand, it's best to seperate business logic from presentation logic and only unit test the business logic?</p>
  
  <p>With that in mind button visibility and messageboxes are presenation logic, right? and are best suited to a manual test plan in which I'll validate the functionality? Is that right?</p>
  
  <p>I'm sure I should unit test if login is succeccful? however, isn't the method dependent on a database? so is that then integration testing? </p>
  
  <p>here's my code </p>
  
  <p><strong>Login form</strong></p>
  
  <pre><code> private void btnLogin_Click(object sender, EventArgs e)
      {
  
  
          //Try and open a connection with database and run the code
          try
          {
  
              //Create new instance of sql connection, pass in the connection string for BayOneSurgerySystem.mdf to connect to database.
              SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\davie\Documents\UniWork\Software Engineering\BayOneSurgerySystem1.0\Database\BayOneSystem.mdf;Integrated Security=True;Connect Timeout=30");
  
              //Create new instance of SQlCommand and pass in a query to be called to retrieve table data for username and passwords aswell as the connection object.
              SqlCommand cmd = new SqlCommand("SELECT * FROM Users WHERE Username = @username and Password = @password", conn);
              //This passes user input into @username and @password
              cmd.Parameters.AddWithValue("@username", txtBoxUsername.Text);
              cmd.Parameters.AddWithValue("@password", txtBoxPassword.Text);
  
              //Open connection with database
              conn.Open();
  
              //Create new instance of dataSet to hold the data retrieved from sql query
              DataSet ds = new DataSet();
              //Create new instance of DataAdpater to retrieve the data pass in Sql command
              SqlDataAdapter da = new SqlDataAdapter(cmd);
              //using DataAdapter fill in dataSet wiht data if user input and stored data matches
              da.Fill(ds);
  
              //Close the connection now data table is filled with username and password
              conn.Close();
  
              //declare bool, true if there is a match with database and user input
              bool loginSuccess = (ds.Tables[0].Rows.Count == 1);
  
  
              //if login success is true then open menu
              if (loginSuccess)
              {
                  /*Change state of enum RoleTypes based on result from dataSet Role_ID column.
                   In UserRole table records are as follows: 
                   Role_ID 1 = PracticeManager
                   2 = Doctor
                   3 = Receptionist*/
  
                  //Print role_ID to console to check that is been set.
                  Console.WriteLine(ds.Tables[0].Rows[0]["Role_ID"]);
  
                  try
                  {
                      //Condition for the switch statement is: check Role_ID from UserRoles table
                      switch (ds.Tables[0].Rows[0]["Role_ID"])
                      {
                          //if the case is that Role_ID for the user logged in is 1 then run the function etc.
                          case 1:
                              {
                                  Roles.Role = Roles.RoleType.practiceManager;
                                  Console.WriteLine("Role type changed to " + Roles.Role);
                              }
                              break;
                          case 2:
                              {
                                  Roles.Role = Roles.RoleType.doctor;
                                  Console.WriteLine("Role type changed to " + Roles.Role);
                              }
                              break;
                          case 3:
                              {
                                  Roles.Role = Roles.RoleType.receptionist;
                                  Console.WriteLine("Role type changed to " + Roles.Role);
                              }
                              break;
                          default:
                              break;
  
                      }
                  }//Switch condition cannot be reached then catch exception and print to console.
                  catch (Exception ex)
                  {
                      Console.WriteLine(ex);
                  }
  
  
                  Console.WriteLine("Logged in.");
                  FrmMenu menu = new FrmMenu();
                  menu.Show();
                  this.Hide();
              }
              else
              {
                  MessageBox.Show("Invalid username or password.", "Error!", MessageBoxButtons.RetryCancel);
                  Console.WriteLine("Not logged in");
              }
  
  
          }
  
          //If connection cant be opened diplsay error message and catch exception and print to console
          catch (Exception ex)
          {
              Console.WriteLine(ex);
              MessageBox.Show("Sorry can't connect");
          }
  
  
  
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Role class</strong></p>
  
  <pre><code> public static class Roles
  {
      /*The RoleType enum is declared here and changed in form login. RoleType is the condition for button visibility
      I.e if roletype is doctor, show doctor buttons*/
      public static RoleType Role;
      public enum RoleType
      {
          practiceManager,
          doctor,
          receptionist
  
      }
  
  
  }
  </code></pre>
  
  <p><strong>Patient form</strong></p>
  
  <pre><code>//if this is clicked, display yesNo messagebox. If yes, logout.
      private void btnLogout_Click(object sender, EventArgs e)
      {
          if (MessageBox.Show("Are you sure?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
          {
              FrmLogin logout = new FrmLogin();
              logout.Show();
              this.Close();
          }
      }
  
      private void FrmPatients_Load(object sender, EventArgs e)
      {
  
          /*Buttons are visible depending on access level. Permissions are as follows:
           * Practice Manager - Patient Records
             Doctor - Register Patient, Patient notes
             Receptionist - New Patient, Register Patient*/
          if (Roles.Role == Roles.RoleType.practiceManager)
          {
              this.btnNewPatient.Visible = false;
              this.btnNotes.Visible = false;
              this.btnSignIn.Visible = false;
  
          }
  
          else if (Roles.Role == Roles.RoleType.doctor)
          {
              this.btnNewPatient.Visible = false;
          }
          else
          {
              this.btnNotes.Visible = false;
          }
  
      }
  
      //if this is clicked return to main menu
      private void pcBxBack_Click(object sender, EventArgs e)
      {
          FrmMenu menu = new FrmMenu();
          this.Close();
          menu.Show();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Test class</strong></p>
  
  <pre><code> [TestClass]
  
       public class LoginTests
       {
         [TestMethod]
           public void Constuctor_NormalData_Login_Is_Successful()
           {
  
              //Arrange
              //Act
              //Assert
            }
  
  
          [TestMethod]
          public void Constructor_RoleTypeEnum_RoleType_Changes()
          {
             //Arrange
             //Act
             //Assert
  
           }
  
  
         }
  </code></pre>
  
  <p>Any advice on what you would use automated testing for?</p>
  
  <p>I've got a manual table with 21 tests validating all messageboxes, button click events and button visibility. </p>
  
  <p>For an A I really need some automated testing. As you can see I've got template for testing role type enum and login succesful, those are the only 2 obvious methods to test that I can see. </p>
  
  <p>Thanks in advance!</p>