vstest icon indicating copy to clipboard operation
vstest copied to clipboard

Cant Run Code Coverage In WinUI3

Open kitUIN opened this issue 10 months ago • 10 comments

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

kitUIN avatar May 13 '25 10:05 kitUIN

@fhnaseer please have a look here :)

nohwnd avatar May 16 '25 10:05 nohwnd

@kitUIN Are you using Visual Studio Enterprise? Or Professional/Community edition?

fhnaseer avatar May 19 '25 07:05 fhnaseer

@kitUIN Are you using Visual Studio Enterprise? Or Professional/Community edition?

Community

kitUIN avatar May 19 '25 07:05 kitUIN

Code coverage components are shipped only with Visual Studio Enterprise edition.

Please download Microsoft.TestPlatform and try vstest.console.exe from this package.

fhnaseer avatar May 19 '25 08:05 fhnaseer

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.。

kitUIN avatar May 19 '25 08:05 kitUIN

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.

Image

Image

fhnaseer avatar May 19 '25 11:05 fhnaseer

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 包中尝试了这个命令,它正确地生成了覆盖率报告。请尝试一下,如果成功请告诉我。

Image

Image

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 秒

kitUIN avatar May 20 '25 01:05 kitUIN

Using.dll will result in the inability to UITest @nohwnd any comments on this?

fhnaseer avatar May 22 '25 07:05 fhnaseer

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.

nohwnd avatar May 22 '25 08:05 nohwnd

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

kitUIN avatar May 22 '25 08:05 kitUIN