Parameterize a Test for Deployment in LegiTest

 

The goal of this walkthrough is to set up a test assembly so that it can be executed in different environments, using different values. This need often arises when a test assembly needs to be deployed from a test creator’s computer to a server or to an integration environment.

We’ll assume that you are using the test assembly from the Comparing Balances and Totals Between Two Tables for this. The steps are similar for any assembly, though.

Please note that video demonstrations serve as a generic guide for various LegiTest capabilities. All of these walkthroughs use the HigherEd and HigherEdDW databases as examples.

Step 1: First, identify the items that you want to parameterize. The most likely candidates are connection or file assets, as these contain values that point to specific locations. In the example test assembly, you’ll want to parameterize the HigherEd and HigherEdDW connection assets.

Step 2: Open up the test suite’s Parameters page. Then, configure a parameter named HigherEdConnection for the HigherEd connection. Provide an appropriate connection string value. Create a mapping between that parameter and the HigherEd connection asset’s ConnectionString property.

Repeat the process for the HigherEdDW connection, using a parameter name of HigherEdDWConnection.

Step 3: Build the project (Build > Build Solution or use the F6 key). This will update the .legitestsettings file associated to the test suite so that it contains the parameters and their assigned values.

Step 4: Now, when the test is executed, the values specified in the .legitestsettings file will be used instead of the direct values specified on the ConnectionString properties.

Please note that if the parameter value is empty or includes whitespace, the directly specified value will still be used.

Step 5: Inside the development environment, you can view the .legitestsettings file in the related output folder for the test suite. After a build, you can also find the .legitestsettings file in the BIN folder.

Step 6: When tests are run, LegiTest will look for .legitestsettings files in the following locations, in order of priority:
a. %UserProfile%\Documents\LegiTest
b. %ProgramData%\PragmaticWorks\LegiTest
c. The folder where the test assembly is located

Step 7: Any parameters with mappings to the test suite found in those locations will be applied to the test assembly. Parameters can also be used without mappings. This can be used if you want to alter only a portion of a property value. For example, if you just wanted to change the Server portion of a connection string, you could do the following:

1. Add a parameter named ServerName, and give it an appropriate value, such as (local).
2. In the connection string property, specify the connection string as:
Server=;Initial Catalog=HigherEd;IntegratedSecurity=SSPI
3. At runtime, the value will be replaced with the value in the .legitestsettings file for the ServerName parameter.

Finally, in some cases, you might want to use environment variables to drive these changing values, without having to use a .legitestsettings file. In that case, you can use the following syntax when specifying the property value, and LegiTest will replace it with the referenced environment variable’s value:

Server=%EnvServerName%;Initial Catalog=HigherEd;IntegratedSecurity=SSPI

Parameters are a useful way to make your tests dynamic, particularly if you need to pass the values in from outside of the test assembly itself. They're particularly useful when supporting multiple environments, such as Development, Test, and Production.

 

Download a Free Trial