Problem
Cannot override environment variables for specific Unit tests project using standard configuration methods in JetBrains Rider's test runner. The Environment Settings section in the Test Runner settings allows to override/add environment variables per solution. One might want to have specific environment variables per exact project (.csproj)
Resolution
To set environment variables for a specific test project, follow these steps:
-
Use a
.runsettingsFile: Create aSampleFileName.runsettingsfile within the same directory as your C# project file (.csproj). -
Add Configuration to the Project File: Integrate the path to the
.runsettingsfile in your project's C# project file by adding the following property:<PropertyGroup> <RunSettingsFilePath>$(MSBuildProjectDirectory)\SampleFileName.runsettings</RunSettingsFilePath> </PropertyGroup> -
Define Environment Variables in
.runsettings: Populate the.runsettingsfile with the desired environment variable values in the following format:<?xml version="1.0" encoding="utf-8" ?> <RunSettings> <RunConfiguration> <EnvironmentVariables> <VariableName1>Value1</VariableName1> <VariableName2>Value2</VariableName2> </EnvironmentVariables> </RunConfiguration> </RunSettings> -
Verify Settings in JetBrains Rider: Launch your test project and confirm that the test runner adheres to the defined environment variables.
Comments
0 comments
Please sign in to leave a comment.