Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runsettings file in visual studio code

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

like image 257
user3032668 Avatar asked Oct 22 '25 22:10

user3032668


2 Answers

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. Test Run Settings setting in VS Code C# configuration

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.

like image 82
Swimburger Avatar answered Oct 25 '25 19:10

Swimburger


Two parts need file .runsettings when you work with VS Code:

  1. when build tests in VS Code, it firstly run vstest.exe with parameters
  2. when run 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")

enter image description here 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>
like image 36
Dongdong Avatar answered Oct 25 '25 19:10

Dongdong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!