user3032668
user3032668

Reputation: 63

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

Upvotes: 4

Views: 13724

Answers (2)

Swimburger
Swimburger

Reputation: 7164

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.

Upvotes: 5

Dongdong
Dongdong

Reputation: 2498

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>

Upvotes: 4

Related Questions