我的项目中有一些单元测试需要 runsettings 文件才能正常运行。
当我启动这些测试时,我遇到了应该从 runsettings 文件中获取的参数问题
我的问题是如何将 runsettings 文件传递给 visual studio 代码以便在我执行测试时使用它?
提前谢谢你,
问候
最佳答案
当您使用 VS Code 时,有两个部分需要文件 .runsettings
:
- 在 VS Code 中进行
build
测试时,首先运行带有参数的vstest.exe
- 在 VS Code 中
运行
测试时,需要mstest.exe
。
对于第一部分,这是 .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")
但是上面的设置是全局的,你可以从 .vscode\workspace.code-workspace
文件为指定的测试项目设置:
{
"folders": [
{
"path": ".."
}
],
"settings": {
"dotnet-test-explorer.testArguments": "--settings .runsettings",
"dotnet-test-explorer.testProjectPath": "**/test.project.name.csproj"
}
}
对于第二部分,我们需要一个新特征RunSettingsFilePath这是从 VS 2019 16.4 交付的。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RunSettingsFilePath>$(MSBuildProjectDirectory)\.runsettings</RunSettingsFilePath> // or $(SolutionDir)
</PropertyGroup>
...
</Project>
关于visual-studio-code - Visual Studio 代码中的运行设置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63397120/