- 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.
- 計算機組成原理與接口技術:基于MIPS架構實驗教程(第2版)
- LibGDX Game Development Essentials
- Building Computer Vision Projects with OpenCV 4 and C++
- 虛擬化與云計算
- MongoDB管理與開發精要
- 分布式數據庫系統:大數據時代新型數據庫技術(第3版)
- MySQL從入門到精通(第3版)
- Lean Mobile App Development
- 深入淺出MySQL:數據庫開發、優化與管理維護(第2版)
- 大數據架構商業之路:從業務需求到技術方案
- 數據庫應用系統開發實例
- 數據庫技術及應用
- R Object-oriented Programming
- 中文版Access 2007實例與操作
- 數據指標體系:構建方法與應用實踐