Reputation: 623
I have a .Net Framework 4.6.2 Unit.Tests project, which has App.config
file, in which it has some passwords in <appSettings>
element. I want to update them in Azure DevOps build pipeline.
I'm using Visual Studio Test task to run the unit test. I tried to update appSettings
in Execution options > Override test run parameters, but it didn't work as expected.
I know that Azure App Service deploy task can update appSettings
in Application and Configuration Settings > App setttings. I want something similar in Visual Studio Test task.
Any idea?
Upvotes: 3
Views: 2599
Reputation: 18546
The "Override Test Run Parameters" section only applies to runsettings
or testsettings
files. It does not apply to app.config files.
Override parameters defined in the TestRunParameters section of runsettings file or Properties section of testsettings file. For example: -key1 value1 -key2 value2. Note: Properties specified in testsettings file can be accessed via the TestContext using Visual Studio 2017 Update 4 or higher
If you want to configure something in the app.config. Try using a "replace tokens" task (there are multiple options).
Our tests usually leverage the runsettings
files. The file syntax is quite similar to the app.config, and you access the values via TestContext
.
<!-- Parameters used by tests at run time -->
<TestRunParameters>
<Parameter name="webAppUrl" value="http://localhost" />
<Parameter name="webAppUserName" value="Admin" />
<Parameter name="webAppPassword" value="Password" />
</TestRunParameters>
[TestMethod]
public void HomePageTest()
{
string appURL = TestContext.Properties["webAppUrl"];
}
Upvotes: 4