Cant Run Code Coverage In WinUI3
I'm following the tutorial(create-winui-unit-test-project) and conducting unit tests, but I find that the code coverage is unavailable
vstest.console.exe bin\x64\Debug\net8.0-windows10.0.19041.0\win-x64\App1.build.appxrecipe /Logger:trx /Settings:test.runsettings /Diag:1.txt
test.runsettings
<RunSettings>
<RunConfiguration>
<DisableAppDomain>True</DisableAppDomain>
</RunConfiguration>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" >
<Configuration>
<Format>cobertura</Format>
<LogLevel>Verbose</LogLevel>
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>False</CollectAspDotNet>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
ther is warning
正在终止进程 ID 为“25004”的应用。
数据收集器“Code Coverage”消息: No code coverage data available. Profiler was not initialized.。
已通过 Scan_Type_ShouldEnqueueFileInfo [9 ms]
已通过 Scan_Generic_ShouldEnqueueFileInfo [< 1 ms]
已通过 Scan_EnumerableTypes_ShouldEnqueueAll [< 1 ms]
已通过 Scan_DirectoryInfo_ShouldEnqueueAll [18 ms]
已通过 Scan_FileInfo_ShouldEnqueue [< 1 ms]
已通过 Scan_Uri_File_ShouldEnqueue [16 ms]
已通过 Scan_Uri_Http_ShouldEnqueue [< 1 ms]
已通过 ScanClear_ShouldClearQueue [< 1 ms]
1.txt 1.datacollector.25-05-13_18-02-17_45836_4.txt 1.host.25-05-13_18-02-19_22102_4.txt
@fhnaseer please have a look here :)
@kitUIN Are you using Visual Studio Enterprise? Or Professional/Community edition?
@kitUIN Are you using Visual Studio Enterprise? Or Professional/Community edition?
Community
Code coverage components are shipped only with Visual Studio Enterprise edition.
Please download Microsoft.TestPlatform and try vstest.console.exe from this package.
If executed in a nuget package it will report an error
正在启动测试执行,请稍候...
在文件 D:\VsProjects\WASDK\ShadowPluginLoader.WinUI\App1\1.txt 中记录 Vstest 诊断
在此运行中,没有为任何源找到合适的测试运行时提供程序。
D:\VsProjects\WASDK\ShadowPluginLoader.WinUI\App1\bin\x64\Debug\net8.0-windows10.0.19041.0\win-x64\App1.build.appxrecipe (UAP,Version=v10.0, X64)
在此运行中,没有为任何源找到合适的测试运行时提供程序。
I copied all the files in the package to the vs folder and executed it, but it still gives me the original error.
数据收集器“Code Coverage”消息: No code coverage data available. Profiler was not initialized.。
Copying to VS folder will not work. Microsoft.TestPlatform nuget package and Microsoft Visual Studio installation folder are not the same. Microsoft Visual Studio required additional coverage components.
I tried this command from the nuget package and it generated coverage report correctly. Please try this out and do let me know if it works or not.
Copying to VS folder will not work. Microsoft.TestPlatform nuget package and Microsoft Visual Studio installation folder are not the same. Microsoft Visual Studio required additional coverage components.复制到 VS 文件夹不起作用。Microsoft.TestPlatform NuGet 包和 Microsoft Visual Studio 安装文件夹不同。Microsoft Visual Studio 需要额外的覆盖组件。
I tried this command from the nuget package and it generated coverage report correctly. Please try this out and do let me know if it works or not.我从 nuget 包中尝试了这个命令,它正确地生成了覆盖率报告。请尝试一下,如果成功请告诉我。
Using.dll will result in the inability to UITest
正在启动测试执行,请稍候...
在文件 D:\VsProjects\WASDK\ShadowPluginLoader.WinUI\App1\1.txt 中记录 Vstest 诊断
总共 1 个测试文件与指定模式相匹配。
数据收集: Logging DataCollector Diagnostics in file: D:\VsProjects\WASDK\ShadowPluginLoader.WinUI\App1\1.datacollector.25-05-20_09-08-30_93087_4.txt
在文件 D:\VsProjects\WASDK\ShadowPluginLoader.WinUI\App1\1.host.25-05-20_09-08-34_22622_4.txt 中记录 TestHost 诊断
已通过 Scan_Type_ShouldEnqueueFileInfo [89 ms]
失败 Scan_Type_Load
错误消息:
“Execute”方法引发了未经处理的异常。请将此错误报告给属性 'Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute' 的作者。
System.InvalidOperationException: UITestMethodAttribute.DispatcherQueue 不应为 null。若要在 WinUI 桌面应用中使用 UITestMethodAttribute,请在测试初始化期间设置静态 UITestMethodAttribute.DispatcherQueue。
at Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute.ExecuteAsync(ITestMethod testMethod) in /_/src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs:line 65
at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodRunner.ExecuteTestAsync(TestMethodInfo testMethodInfo) in /_/src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs:line 461
已通过 Scan_Generic_ShouldEnqueueFileInfo [< 1 ms]
已通过 Scan_EnumerableTypes_ShouldEnqueueAll [< 1 ms]
已通过 Scan_DirectoryInfo_ShouldEnqueueAll [19 ms]
已通过 Scan_FileInfo_ShouldEnqueue [< 1 ms]
已通过 Scan_Uri_File_ShouldEnqueue [21 ms]
已通过 Scan_Uri_Http_ShouldEnqueue [< 1 ms]
已通过 ScanClear_ShouldClearQueue [1 ms]
结果文件: D:\VsProjects\WASDK\ShadowPluginLoader.WinUI\App1\TestResults\15854_KITUIN_2025-05-20_09_08_37.trx
附件:
D:\VsProjects\WASDK\ShadowPluginLoader.WinUI\App1\TestResults\f664aee2-d5d2-4b43-b489-5fa274a9a8b1\15854_KITUIN_2025-05-20.09_08_37.cobertura.xml
测试运行失败。
测试总数: 9
通过数: 8
失败数: 1
总时间: 7.0412 秒
Using.dll will result in the inability to UITest @nohwnd any comments on this?
You have to point the console to App1.build.appxrecipe to run via the uwp test runtime provider, if you use dll it will choose the desktop test runtime provider, which does not host the app correctly.
If executed in a nuget package it will report an error如果在 nuget 包中执行会报错
正在启动测试执行,请稍候... 在文件 D:\VsProjects\WASDK\ShadowPluginLoader.WinUI\App1\1.txt 中记录 Vstest 诊断 在此运行中,没有为任何源找到合适的测试运行时提供程序。 D:\VsProjects\WASDK\ShadowPluginLoader.WinUI\App1\bin\x64\Debug\net8.0-windows10.0.19041.0\win-x64\App1.build.appxrecipe (UAP,Version=v10.0, X64) 在此运行中,没有为任何源找到合适的测试运行时提供程序。I copied all the files in the package to the vs folder and executed it, but it still gives me the original error.我把包里的所有文件复制到 vs 文件夹并执行它,但它仍然给我原来的错误。
数据收集器“Code Coverage”消息: No code coverage data available. Profiler was not initialized.。
However, once the App1.build.appxrecipe is used, the above error will occur. I haven't found any solution for the time being It's normal (as in vs) if code coverage is not enabled, but I precisely need code coverage