UWP C++单元测试项目中Logger输出失效问题求助
UWP C++/CX单元测试项目Logger功能失效问题
在Visual Studio 2022的通用Windows(UWP)解决方案中,C++/CX单元测试应用项目的Logger功能完全失效——无论是测试详情的摘要窗口,还是输出窗口(尤其是“测试”分类下),都无法找到Logger的输出内容。
重现代码
新项目中仅添加一行简单代码即可重现问题:
Logger::WriteMessage(L"**My Testing Message**");
已尝试的排查操作
- 查阅Visual Studio C++单元测试框架文档,但UWP单元测试相关文档主要针对C#,未提及Logger的使用细节
- 在“视图>其他窗口”中排查所有输出窗口,未发现Logger输出的去向
- 检查测试资源管理器中含“日志”“输出”关键词的选项,启用日志并设置发送到跨平台日志,但测试运行时该窗口始终为空
- 测试资源管理器显示单元测试项目运行正常(绿灯标识),Assert功能可正常工作
- 新建第二个UWP单元测试应用项目,仅在测试方法中添加Logger代码行,项目可正常构建且被测试资源管理器识别,但依旧无法找到Logger输出
编辑:尝试通过.runsettings配置增强日志功能,但查看TestResults文件夹中的日志文件后,仍未发现Logger输出(仅日志中的测试时长显示为精确值,而非“<1ms”)。配置内容如下:
<?xml version="1.0" encoding="utf-8"?> <RunSettings> <!-- Configurations that affect the Test Framework --> <RunConfiguration> <!-- Use 0 for maximum process-level parallelization. This does not force parallelization within the test DLL (on the thread-level). You can also change it from the Test menu; choose "Run tests in parallel". Unchecked = 1 (only 1), checked = 0 (max). --> <MaxCpuCount>1</MaxCpuCount> <!-- Path relative to directory that contains .runsettings file--> <ResultsDirectory>\.\TestResults</ResultsDirectory> <!-- Omit the whole tag for auto-detection. --> <!-- [x86] or x64, ARM, ARM64, s390x --> <!-- You can also change it from the Test menu; choose "Processor Architecture for AnyCPU Projects" --> <TargetPlatform>x64</TargetPlatform> <!-- Any TargetFramework moniker or omit the whole tag for auto-detection. --> <!-- net48, [net40], net6.0, net5.0, netcoreapp3.1, uap10.0 etc. <TargetFrameworkVersion></TargetFrameworkVersion>--> <!-- Path to Test Adapters %SystemDrive%\Temp\foo;%SystemDrive%\Temp\bar <TestAdaptersPaths></TestAdaptersPaths>--> <!-- TestCaseFilter expression <TestCaseFilter>(TestCategory != Integration) & (TestCategory != UnfinishedFeature)</TestCaseFilter>--> <!-- TestSessionTimeout was introduced in Visual Studio 2017 version 15.5 --> <!-- Specify timeout in milliseconds. A valid value should be greater than 0 --> <TestSessionTimeout>10000</TestSessionTimeout> <!-- true or false --> <!-- Value that specifies the exit code when no tests are discovered --> <TreatNoTestsAsError>true</TreatNoTestsAsError> </RunConfiguration> <!-- Configurations for data collectors --> <DataCollectionRunSettings> <DataCollectors> <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <Configuration> <CodeCoverage> <ModulePaths> <Exclude> <ModulePath>.*CPPUnitTestFramework.*</ModulePath> </Exclude> </ModulePaths> <!-- We recommend you do not change the following values: --> <UseVerifiableInstrumentation>True</UseVerifiableInstrumentation> <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses> <CollectFromChildProcesses>True</CollectFromChildProcesses> <CollectAspDotNet>False</CollectAspDotNet> </CodeCoverage> </Configuration> </DataCollector> <!-- Configuration for blame data collector --> <DataCollector friendlyName="blame" enabled="false"> </DataCollector> </DataCollectors> </DataCollectionRunSettings> <!-- Parameters used by tests at run time --> <TestRunParameters> <Parameter name="webAppUrl" value="http://localhost" /> <Parameter name="webAppUserName" value="admin" /> <Parameter name="webAppPassword" value="" /> </TestRunParameters> <!-- Configuration for loggers --> <LoggerRunSettings> <Loggers> <Logger friendlyName="console" enabled="True"> <Configuration> <Verbosity>verbose</Verbosity> </Configuration> </Logger> <Logger friendlyName="trx" enabled="True"> <Configuration> <LogFileName>foo.trx</LogFileName> </Configuration> </Logger> <Logger friendlyName="html" enabled="True"> <Configuration> <LogFileName>foo.html</LogFileName> </Configuration> </Logger> <Logger friendlyName="blame" enabled="True" /> </Loggers> </LoggerRunSettings> <!-- Adapter Specific sections --> </RunSettings>
内容的提问来源于stack exchange,提问作者Gabe Fernandez
相关产品推荐
相关产品推荐

