I have some unit tests in my project that needs runsettings file to run properly.
When I launch those tests, I have issues with parameters that should be taken from the runsettings file
My question is how can I pass the runsettings file to visual studio code in order to use it when I execute my tests ?
Thank you in advance,
Regards
If you're using the C# extension for VS Code, there's a setting to configure your .runsettings file. Go into VS Code's settings and search '.runsettings'. This should show the "Omnisharp: Test Run Setting" setting under the Extensions > C# configuration node.

I suggest clicking on the "Workspace" tab, so the setting is stored in your project instead of your user. That way, you can also check these settings into git.
Two parts need file .runsettings when you work with VS Code:
build tests in VS Code, it firstly run vstest.exe with parametersrun tests in VS Code, it need mstest.exe.For the first part, here is the document for .NET Core Test Explorer: https://github.com/formulahendry/vscode-dotnet-test-explorer
The settings are available via File / Preferences / Settings. Navigate to extensions and .NET Core test explorer.
Additional arguments that are added to the dotnet test command. These can for instance be used to collect code coverage data ("/p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=../../lcov.info") or pass test settings ("--settings:./myfilename.runSettings")
But above settings are global, you can setup from .vscode\workspace.code-workspace file for specified test project only:
{
"folders": [
{
"path": ".."
}
],
"settings": {
"dotnet-test-explorer.testArguments": "--settings .runsettings",
"dotnet-test-explorer.testProjectPath": "**/test.project.name.csproj"
}
}
For the second part, we need a new feature RunSettingsFilePath that's delivered from VS 2019 16.4.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RunSettingsFilePath>$(MSBuildProjectDirectory)\.runsettings</RunSettingsFilePath> // or $(SolutionDir)
</PropertyGroup>
...
</Project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With