Visual Studio 代码中的运行设置文件 [英] Runsettings file in visual studio code
问题描述
我的项目中有一些单元测试需要运行设置文件才能正常运行.
当我启动这些测试时,我遇到了应该从 runsettings 文件中获取的参数的问题
我的问题是如何将 runsettings 文件传递给 Visual Studio 代码,以便在执行测试时使用它?
先谢谢你,
问候
使用 VS Code 时需要两部分文件 .runsettings
:
- 在VS Code中
build
测试时,首先运行vstest.exe
,带参数 - 在VS Code中
run
测试时,需要mstest.exe
.
对于第一部分,这里是 .NET Core 测试资源管理器的文档:但以上设置是全局的,您可以从 .vscode\workspace.code-workspace
文件中为指定的测试项目进行设置:
<代码>{文件夹":[{路径":.."}],设置":{dotnet-test-explorer.testArguments":--settings .runsettings",dotnet-test-explorer.testProjectPath":**/test.project.name.csproj"}}
对于第二部分,我们需要一个新功能 RunSettingsFilePath.
<属性组><RunSettingsFilePath>$(MSBuildProjectDirectory)\.runsettings</RunSettingsFilePath>//或 $(SolutionDir)</PropertyGroup>...</项目>
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
Two parts need file .runsettings
when you work with VS Code:
- when
build
tests in VS Code, it firstly runvstest.exe
with parameters - when
run
tests in VS Code, it needmstest.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>
这篇关于Visual Studio 代码中的运行设置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!