DeploymentTransformation¶
This element is used to define transformations, which you can also apply to your configuration file (app.config
) when using the Full Framework in your project. Note that you cannot transform the configuration file in .NET Core projects, as .NET Core does not support app.config.
Transformations can be nested within a <Target>
element, allowing you to define different configuration settings per target, e.g. for different platforms (x64/x86) or for different web browsers. You can also use {Target}
as a placeholder for this value, in which case the placeholder is replaced with the target name.
Note: When running tests in in multiple threads, you need to ensure that each thread is accessing a different file, or you will encounter conflicts. Use RelocateConfigurationFile
in conjunction with the {TestThreadID}
placeholder to achieve this.
The following elements and attributes are available:
Element/Attribute | Required/Optional | Description |
---|---|---|
GlobalSteps | Optional | Deployment transformation steps that are applied globally. Global steps are only applied once. |
Steps | Required | Deployment transformation steps for your configuration file. |
Each step can contain the following elements:
Element/Attribute | Required/Optional | Description |
---|---|---|
CopyFolder | Optional | Copies a specific folder to the test run instance:source : Source folder to copytarget : Target folderdeleteFolderOnRestore : Determines whether the folder is deleted if an error occurs during the test run (default=true).Example: <CopyFolder source="%TMP%\SpecRunTestSource" target="%TMP%\SpecRunTestCopy" /> |
ConfigFileTransformation | Optional | Note: Not available in .NET Core projects, as this affects app.config !Defines the transformation applied to the configuration file. configFile : the configuration file to transform (optional)Transformation: The transformation applied to the file. |
Relocate | Optional | Changes the location where the tests run, allowing you to continue developing while your tests run (as the bin/debug folder is no longer used to execute tests).targetFolder : The folder the application is moved to for testing. Moving this to another folder than /bin/debug means you can continue working in Visual Studio while the tests run.deleteFolderOnRestore : Determines whether the folder is deleted if an error occurs during the test run. |
RelocateConfigurationFile | Optional | Note: Not available in .NET Core projects, as this affects app.config !target : The target location of the relocated config file relative to the base folderRelocating your configuration file creates a copy of the test assembly configuration file, allowing each thread to be configured differently. It makes sense to include the {TestThreadId} placeholder in the relocated file's name so that a different file is used by each thread. Note: Any transformations applied to your default configuration file are also applied to the relocated files. |
Custom | Optional | You can write your own deployment steps that are executed. The corresponding class must implement TechTalk.SpecRun.Framework.IDeploymentTransformationStep .Add a <Custom> element for each step containing the following attributes:type : The type that implements the custom step in the format Path, DLL , where Path includes the namespace and corresponding class (e.g. DeploymentSteps.MySteps ) and where DLL is the name of the assembly containing the class.arguments : The arguments used by the custom step. If this is a string, the string can be accessed via DeploymentContext.CustomData.Note: In order to access your custom steps, the DLL containing the steps needs to be present in your output folder. You can ensure this is the case by adding a reference to your solution. |
IISExpress | Optional | Used to test web applications. Atributes: 'webAppFolder': The path to the web application you want to test. iisExpressPath : The path to IISExpress (default = %ProgramFiles%\IIS Express\iisexpress.exe ).port : The port used by IISExpress to listen for requests (default = 8080).useShellExecute : Determines whether to start IISExpress with or without the shell. |
DeleteFolder | Optional | Deletes the specified folderpath : The path of the folder to be deleted (relative to the base folder).Example: <DeleteFolder path="%USERPROFILE%\.nuget\packages\SpecRun.SpecFlow" /> |
EnvironmentVariable | Optional | Defines an environment variablevariable : The name of the environment variable.value : The value of the environment variable.Example: <EnvironmentVariable variable="Test_Browser" value="Firefox" /> Note: If you run multiple targets in parallel using multiple test threads you have to use Process test thread isolation to avoid race conditions between the test threads trying to access the same environment variable. |
Example¶
<DeploymentTransformation>
<Steps>
<ConfigFileTransformation configFile="App.config">
<Transformation>
<![CDATA[<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="foo" value="bar" xdt:Locator="Match(key)" xdt:Transform="Insert"/>
</appSettings>
</configuration>
]()>
</Transformation>
</ConfigFileTransformation>
</Steps>
</DeploymentTransformation>