Monday, December 22, 2014

How to create automated testing tool

As usual, I always cited my reference. :) As an appreciation of others' hardwork.

With the previous post about create test project and  record coded UI, I found that it is hassle to create. Also, transferring or sharing the testing methods among testers is not convenient. If you faced the same issue, maybe it is time to look for , or build testing tool on your own.

A very super duper simple testing tool can look like this.


The concept is basically:

First, load the application,
Second, browser for the test data ( saved in some file format, able to share and reuse in any machine)
Third, look at the screen for the test result, i.e. test passed or failed.

Read more if you want to know how to load from excel and loop each of them.

to read the data from excel:

Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkBook = xlApp.Workbooks.Open(file, 0, true, 5, "", "",
true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false,                                                 false, 0, true, 1, 0);
Excel.Worksheet xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
Excel.Range range = xlWorkSheet.UsedRange;

string[,] testData = new string[range.Rows.Count, range.Columns.Count];

for (int i = 1; i <= range.Rows.Count; i++)
{
for (int j = 1; j <= range.Columns.Count; j++)
{
testData[i-1, j-1] = (string)(range.Cells[i, j] as Excel.Range).Value2 ;;
}
}


To loop on each row of the 2D array, I made it to be in another function :

private void excecuteTest(string[,] testData)
{
object[] p = {this, new EventArgs()};
for (int i = 1; i <= testData.GetUpperBound(0); i++)
{
InvokeMethod(testForm, testData[i, (int)testArrayFields.EventMethodName].ToString(), p);
label5.Text = testData[i, (int)testArrayFields.TestFunctionName].ToString();
string actualResult = (string)(GetProperty(GetField(testForm,
testData[i, (int)testArrayFields.CheckingFieldName].ToString()),
testData[i, (int)testArrayFields.FieldTypeName].ToString()));
string expectedResult = testData[i, (int)testArrayFields.ExpectedResult].ToString();
label4.Text = (actualResult == expectedResult) ? "success" : "fail";
};
}

No comments:

Post a Comment