- Learning Software Testing with Test Studio
- Rawane Madi
- 727字
- 2021-08-06 16:46:18
Functional random keyword-driven tests
All the test cases so far address one type of operation in the application. We have seen how to compare two new files, map the application folder, filter on history, and compare using the default feature. On the whole, we have four main operations. Generally, the user will rarely start the application to perform one operation and then close it. Furthermore, we might want to automate the requirement's use cases that describe user scenarios composed from many operations. The two use cases are illustrated as follows:
- Use case one:
- Open an application.
- Map the application folder.
- Compare files using the default feature.
- Check history.
- Use case two:
- Open an application.
- Compare files using the new files option.
- Check history.
- Map the application folder.
These use cases are nothing but a rearrangement of the basic application functions we listed previously. They also form keyword sets where each numbered bullet maps to one File Comparer
function. So we are going to address each function as an atomic unit. Any unique combination of the atomic functions could serve as an automated keyword test and this is exactly what we are going to see in this section.
Let us picture for a second the keyword test structure. The first task is to generate the sequence of random keywords. The second task is to loop over this sequence and call the corresponding tests.
The three new notions that we need to take care of are as follows:
- Introducing the random factor in the test
- Saving the randomly generated output into a structure that will be visible to all the test steps
- Dynamically calling the random tests
Theoretically, we are going to map each basic test from the atomic functions to an integer that starts with 0
and increases by 1
as follows:
- Value
0
representsFunc-1_FileCompare_Equal_Successful
- Value
1
representsFunc-2_FileCompare_DefaultComparison_Successful
- Value
2
representsFunc-3_FileCompare_MapFolder_Successful
- Value
3
representsFunc-4_History_SingleDate_Successful
Create a folder under the Automated Test Scripts
folder called Keyword Tests
and then add a WPF test called KeywordTests_Random
. Open the test and add a coded step called to it and then edit the underlying function's name to KeywordTests_Random_KeywordTestManager
. This function will, as its name suggests, produce the random number sequence. In the following way, we would have catered the preceding first notion:
[CodedStep(@"Generating random number sequence")] public void KeywordTests_Random_KeywordTestManager() { Random random = new Random(); InfoHolder.tests = new int[]{random.Next(3), random.Next(3), random.Next(3), random.Next(3)}; }
The generated number sequence is saved in the InfoHolder.tests
structure. This structure is accessible inside all the subsequent coded steps since it will be created in a static class, meaning that there will be only one instance of it throughout the life span of the test. Add this code to the beginning of the class right before the public class KeywordTests_Random
statement:
public static class InfoHolder { public static int[] tests = new int[4]; public static int testNum; }
The tests
integer array will be populated with the random numbers generated when the KeywordTests_Random_KeywordTestManager
method executes. The testNum
variable is going to hold the index of the loop that will dynamically call the tests based on their mapped number. At any time, this variable is strictly less than four. With this, we have implemented the second notion.
From the Logical button of the Add ribbon, add a loop after the [CodedStep(@"Generating random number sequence")] test step and set the value of its count to 4
. Finally, add the following coded step, which is responsible for dynamically calling the keyword test and dragging it inside the loop block:
[CodedStep(@"Execute Random Test")] public void KeywordTest_RandomTest() { string testToExecute = String.Empty; switch (InfoHolder.tests[InfoHolder.testNum]) { case 0: testToExecute = "Automated Test Scripts\\Functional Tests\\Func-1_FileCompare_Equal_Successful.tstest"; break; case 1: testToExecute = "Automated Test Scripts\\Functional Tests\\Func-2_FileCompare_DefaultComparison_Successful.tstest"; break; case 2: testToExecute = "Automated Test Scripts\\Functional Tests\\Func-3_FileCompare_MapFolder_Successful.tstest"; break; case 3: testToExecute = "Automated Test Scripts\\Functional Tests\\Func-4_History_SingleDate_Successful.tstest"; break; } InfoHolder.testNum++; Log.WriteLine("Executing Keyword test"); this.ExecuteTest(testToExecute); }
The switch case
block assigns the physical file path to the testToExecute
variable, based on the theoretical numbering of the atomic functions. This variable is the parameter of the built-in Test Studio framework's Execute
method. When it executes, it will call the automated test, which will run under the KeywordTests_Random
scope. With this step we have finalized the preceding three notions.
Set up the test, so that it launches the File Comparer
application using the Configure button and then run it.
- 程序員修煉之道:從小工到專家
- 數(shù)據(jù)庫原理及應(yīng)用教程(第4版)(微課版)
- 輕松學(xué)大數(shù)據(jù)挖掘:算法、場景與數(shù)據(jù)產(chǎn)品
- MongoDB管理與開發(fā)精要
- SQL Server 2008數(shù)據(jù)庫應(yīng)用技術(shù)(第二版)
- 圖解機(jī)器學(xué)習(xí)算法
- 揭秘云計(jì)算與大數(shù)據(jù)
- 數(shù)據(jù)驅(qū)動(dòng):從方法到實(shí)踐
- Proxmox VE超融合集群實(shí)踐真?zhèn)?/a>
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)教程上機(jī)指導(dǎo)與習(xí)題集(微課版)
- SQL應(yīng)用及誤區(qū)分析
- 探索新型智庫發(fā)展之路:藍(lán)迪國際智庫報(bào)告·2015(下冊(cè))
- 數(shù)據(jù)庫應(yīng)用系統(tǒng)開發(fā)實(shí)例
- Gideros Mobile Game Development
- Unity for Architectural Visualization