In this chapter, apply what you learned about test suites in the previous chapters.
To do so, build a simple test using the various test suite items.
Theme: Build a test
Time: 15 minutes
Install the sample solution:
-
Unzip to any folder on your computer.
-
Start Ranorex Studio and open the solution file
RxDatabase.rxsln
Define the test
Before start building the test, you need to define what it will do. Keep it simple, so your test only adds an entry to a database and then validates whether it’s been added.
Our AUT will be the Ranorex Demo Application. The required steps are as follows:
- Start the Ranorex Demo Application.
- Click the Test database tab.
- Enter the first name in the First name field.
- Enter the last name in the Last name field.
- Select the department from the Department drop-down.
- Enter the age in the Age field.
- Select a gender from the Gender box.
- Click Add Entry.
- Validate that Number of entries has changed from 0 to 1.
- Exit the Ranorex Demo Application.
Review the recording modules
The sample solution already contains the required recording modules. Let’s take a look at them.
The modules are organized in two folders. The application functions folder contains the modules needed to control the application itself, for example, starting and exiting the Ranorex Demo Application. The database functions folder contains the modules related to adding an entry to the database.
The modules in these folders are quite specific, as you can see from their names. They each contain only the actions necessary for an individual step in our test definition. Modules built in this way are easier to reuse. This gives you more flexibility when building tests.
Assemble the test
Everything is ready, so let’s get to business and start building our test. There is one test suite in the project, RxDatabase.rxtst.
It should already be open. If it is not, double-click the file in the project view.
Add a setup region
In the test suite view, you’ll see that the test suite is mostly empty, except for a single test case with the default name. The test definition lists starting the AUT as the first step, so that’s what you add first. Starting the AUT is a perfect example of a module to include in a global setup region because, without it, no other test steps work. To add a global setup region:
-
In the test suite view, right-click the test suite and click Add setup.
-
From the module browser, drag the module StartAUT to the setup region. In addition to starting the demo application, the StartAUT module also clicks on the Test database tab, which is step 2 from our test definition.
Add the database test
Steps 3 to 9 in the test definition represent adding an entry to the database and validating it. This is the core of our test, so it should get its test case. Use the existing test case, but let’s first give it a more meaningful name. To rename it, check the instructions below:
-
Click the test case and press
F2
. -
Rename it to SimpleDatabaseTest and click
Enter
.
Now, you can fill the test case with the required modules. These are, in test definition order: InsertName, SelectDepartment, InsertAge, SelectGender, AddEntry, and ValidateEntries. You can add the first four modules in any order you like, but AddEntry must be second to last, and ValidateEntries must be last.
To add the modules:
-
From the module browser, drag the modules to the test case.
-
- You can add them individually or select several modules at once using
Ctrl
+ Click. - If you misplace a module in the test suite view, simply drag it to its correct place.
- You can add them individually or select several modules at once using
Create a module group
The modules InsertName, InsertAge, SelectGender, and SelectDepartment are all part of the same process: defining the data that will be added to the database, in other words, inserting a person. This is why it makes sense to organize them in a module group. This way, you won’t have to add all four modules over and over again when you create more test cases where this process is needed. To add the modules to a module group:
-
In the Test suite view, select the four modules using
Ctrl
+ Click orShift
+ Click. -
Right-click the modules, and click Group selected modules.
-
The newly created module group opens in the module group view.
-
Rename the module group to InsertPerson and close it.
-
The test case now contains the module group InsertPerson and the module group also appears in the module browser for reuse.
Add a smart folder
As tests grow larger and more complex, it can become difficult to manage the test suite.
Smart folders are a useful structuring item to overcome this issue. Instead of filling a test case with 50 modules that all logically belong to the same test, add smart folders to the test case and organize the modules in them. Smart folders also make it easy to exclude particular parts of a test case from being run during test execution. This is exactly what we use a smart folder for in our example. You might not always want the validation to be carried out, so it will get its smart folder.
To add ValidateEntries to a smart folder:
-
Right-click the test case SimpleDatabaseTest and click Add > New smart folder.
-
Drag ValidateEntries to the new smart folder.
-
Rename the smart folder to Validation.
Add a teardown region
Our test is almost complete. You only need to add the last step, exiting the Ranorex Demo Application. This is a perfect example of a step that should be in a global teardown region because, after it, no other test actions can be performed. The system is restored to its state before the test. Normally, this would also include deleting all entries made, but the database doesn’t save any entries when exiting, so you don’t need to include this action. To add the teardown region:
-
In the test suite view, right-click the test suite and click Add teardown.
-
From the module browser, drag the module ExitAUT to the teardown region.
Run the test
Congratulations, you’ve just built a test in the test suite. You can apply the basic principles of this tutorial to any other test you create.
This is the point where you’ll run your test. We’ll cover the details and advanced options for running tests in the next chapter, Execute a test suite. For now, just press the large RUN button in the test suite view and enjoy your database test execution!