Using Environment Variables in Generic Tests

To program a generic test, you type information into fields on the generic test page. In several of these fields, you type paths to folders. Although you can hard-code these paths, you can also use environment variables to represent paths in the following fields:

  • target executable

  • command-line arguments

  • summary results file location

  • deployment items

You can use any system-defined or user-defined environment variable, such as SystemDrive, ProgramFiles, and UserProfile. An especially useful variable is ComSpec. ComSpec expands to the full path of cmd.exe, which is the command prompt executable. You can use ComSpec for running command prompt scripts such as .bat files.


Environment variables are not case sensitive.

To determine which environment variables are set and the values they have, type set at a command line.

By default, undefined environment variables are expanded to an empty string. For example, if you specify %MyExecutableDir%MyExecutable.exe in a generic test, but MyExecutableDir is not defined, the test engine treats this string as MyExecutable.exe and tries to run it in the deployment directory. This works if MyExecutable.exe was deployed.

You can use an environment variable to control the folder in which the test engine runs a test. For example, if you set MyExecutableDir to E:\builds\drop\...\Bin\, the test engine tries to run the file in that location. This technique is useful if a test cannot be moved, which could be the case if the test is under source control.

See Also


Using a Summary Results File with a Generic Test

Other Resources

Generic Tests Settings Examples