Sample GUI Test Automation for Adding 2 Integers in .NET

SampleData.txt inside bin/debug project folder
000:Add:1 2:3
001:Add:2 1:3
002:Add:0 0:0

003:Add:-1 2:1
004:Add:1 -2:-1
005:Add:-1 -2:-3

006:Add:11 22:33
//:007:Add:0 99999999999999:99999999999999
//:008:Add:-99999999999999 0:-99999999999999
//:009:Add:-99999999999999 99999999999999:0

//:010:Add:11.1 22.1:33.3
//:011:Add:1.1 2:3.1
//:012:Add:1 2.2:3.2

013:Add:3:3
014:1 2:3
015:Sdd:1 2:3
016:Add:1 2:4
//:017:Add:a b:ab

form1 with info and button1 to run the API test for adding.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace API_testing_for_adding_2_numbers
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
new ResultForm().Show();
}
}
}

//form 2 as ResultForm with richtext box as txtanswer in the form to display output

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace API_testing_for_adding_2_numbers
{
public partial class ResultForm : Form
{
public ResultForm()
{
InitializeComponent();
}

private void ResultForm_Load(object sender, EventArgs e)
{
String answer = “”;
try
{
FileStream fs = new FileStream(”SampleData.txt”, FileMode.Open);
StreamReader myfile = new StreamReader(fs);
String line;
answer = “Count: Operation: input: output : Result”;
int output = 0, sum = 0;
string funcname, input;
String[] arr = new String[2];
bool flag = false;
while ((line = myfile.ReadLine()) != null)
{
flag = true;
if (line.Length == 0)
answer = answer + “\n”;
else
{
String[] tokens = line.Split(’:');
if (tokens.Length == 4)
{
funcname = tokens[1];
input = tokens[2];
output = Int32.Parse(tokens[3]);
if (funcname.Equals(”Add”))
{
arr = input.Split(’ ‘);

if (arr.Length == 2)
{
sum = Program.Add(Int32.Parse(arr[0]), Int32.Parse(arr[1]));
}
else flag = false;
}
else flag = false;

if (flag == false)
answer = answer + “\n” + line + “: Invalid Input”;
else
{
if (sum == output)
answer = answer + “\n” + line + “: TRUE”;
else
answer = answer + “\n” + line + “: False”;
}

}
else
answer = answer + “\n” + line + “: Invalid Input”;
}
}
txtanswer.Text = answer;
}
catch(Exception ee)
{
txtanswer.Text = answer + “\n” + ee.Message;

}
}
}
}

No comments:

Post a Comment