在本页

测试适配器设置

.runsettings 文件的结构是一个 XML 文档。根元素<RunSettings> 包含测试框架的特定设置。<QtTest> 元素包含 Qt 单元测试的设置。

有关在 Visual Studio 中使用 .runsettings 文件的更多信息,请参阅通过使用 .runsettings 文件配置单元测试。

必选元素

必须在<QtTest> 元素中设置 Qt 版本。

名称描述示例
QtInstall指定用于构建和运行测试的 Qt 版本。<QtInstall>$(DefaultQtVersion)</QtInstall>

最小运行设置示例

<RunSettings>
    <QtTest>
        <QtInstall>$(DefaultQtVersion)</QtInstall> <!-- Mandatory -->
    </QtTest>
</RunSettings>

可选元素

下表列出了<QtTest> 元素中的可选元素。

名称描述出现默认值示例
启用适配器启用或禁用 Qt Test 适配卡。一次true<EnabledAdapter>true</EnabledAdapter>
显示适配器输出在Output >Tests 中显示测试适配器的输出。一次false<ShowAdapterOutput>false</ShowAdapterOutput>
测试超时以毫秒为单位设置单个测试的超时时间。值为 -1 表示无超时。一次-1<TestTimeout>-1</TestTimeout>
发现超时设置测试发现的超时时间(毫秒)。值为 -1 表示无超时。一次2000<DiscoveryTimeout>2000</DiscoveryTimeout>
解析 PdbFiles解析 PDB 文件以获取测试函数的源文件和行号。一次true<ParsePdbFiles>true</ParsePdbFiles>
仅子系统控制台仅扫描控制台二进制文件以查找 Qt Test 函数。一次true<SubsystemConsoleOnly>true</SubsystemConsoleOnly>

输出部分

控制测试运行期间生成的日志的位置和格式。

名称说明出现示例
文件名格式定义写入测试结果的方式和位置。支持的输出格式有:txt、csv、junitxml、xml、lightxml、teamcity 和 tap。多重<FilenameFormat>PATH,OUTPUTFORMAT</FilenameFormat>

字斟句酌部分

影响测试运行期间生成的日志的详细程度。

名称描述发生默认值示例
级别测试日志中报告的详细程度。一次为空<Level>silent</Level> 表示最小输出。
日志信号记录所有发出的信号以及这些信号导致的槽调用。一次false<LogSignals>false</LogSignals>

命令部分

影响测试运行方式并控制测试执行环境。

命令名称说明发生默认值示例
事件延迟控制事件模拟中的延迟。一次-1<EventDelay>-1</EventDelay>
按键延迟控制事件模拟中的延迟。一次-1<KeyDelay>-1</KeyDelay>
鼠标延迟控制事件模拟中的延迟。一次-1<MouseDelay>-1</MouseDelay>
最大警告数要输出的最大警告次数。一次2000<MaxWarnings>2000</MaxWarnings>
NoCrashHandler启用或禁用 Windows 错误报告对话框。一次false<NoCrashHandler>false</NoCrashHandler>

.runsettings 文件示例

下面的 XML 显示了默认 Qt .runsettings 文件的内容。<QtInstall> 是必须的,所有其他元素或部分都是可选的,因为 Qt Test adapter 提供了默认值。

<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<!-- For more information, see https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2022  -->
<RunSettings>
    <QtTest>

        <!-- "The Qt version used to build and run the tests. -->
        <QtInstall>$(DefaultQtVersion)</QtInstall> <!-- Mandatory. -->

         <!-- Enables or disables showing all output generated by the test adapter into the default
              'Output | Tests' pane. The default value is false. -->
        <ShowAdapterOutput>false</ShowAdapterOutput> <!-- Optional. -->

        <!-- Terminates a running test if it exceeds the specified timeout in milliseconds.
             A timeout of -1 means the test will not be terminated. The default value is -1. -->
        <TestTimeout>-1</TestTimeout>  <!-- Optional. -->

        <!-- Terminates a running discovery if it exceeds the specified timeout in milliseconds.
             A timeout of -1 means the test will not be terminated. The default value is 2000. -->
        <DiscoveryTimeout>2000</DiscoveryTimeout>  <!-- Optional. -->

        <!-- Enables or disable parsing of PDB files to retrieve the source file and line number
             of test functions for an executable. The default value is true. -->
        <ParsePdbFiles>true</ParsePdbFiles> <!-- Optional. -->

        <!-- Scan only console binaries (/SUBSYSTEM:CONSOLE) for Qt test functions. Set to false to
             scan all binary types at the cost of longer discovery time. The default value is true. -->
        <SubsystemConsoleOnly>true</SubsystemConsoleOnly> <!-- Optional. -->

        <!-- Allows multiple FilenameFormat tags for specifying different output files and formats. -->
        <Output> <!-- This section is optional. -->
            <!--
                 Writes the test output to the specified file using the specified output format.
                 Supported output formats: txt, csv, junitxml, xml, lightxml, teamcity, tap. Needs
                 to follow this convention:

                 <FilenameFormat>PATH,OUTPUTFORMAT</FilenameFormat>
            -->
        </Output>

        <!-- Control how much detail is reported in test logs. -->
        <Verbosity> <!-- This section is optional. -->
            <!--
                 Supported values: silent, v1, v2
                     silent: only shows fatal errors, test failures and minimal status messages.
                     v1: shows when each test function is entered. Only affects plain text output.
                     v2: Extended verbose output; shows each QCOMPARE() and QVERIFY(). This option
                         affects all output formats and implies -v1 for plain text output.
                    "The default value is empty."
            -->
            <Level></Level> <!-- Optional. -->

            <!-- Enables or disables logging all signals that get emitted and the slot invocations
                 resulting from those signals. The default value is disabled. -->
            <LogSignals>false</LogSignals> <!-- Optional. -->

        </Verbosity>

        <!-- The following command-line options influence how tests are run. -->
        <Commands> <!-- This section is optional. -->

            <!-- If no delay is specified for keyboard or mouse simulation
                 (QTest::keyClick(), QTest::mouseClick() etc.), the value from this parameter
                 (in milliseconds) is substituted. The default value is -1. -->
            <EventDelay>-1</EventDelay> <!-- Optional. -->

            <!-- Like 'EventDelay', but only influences keyboard simulation and not mouse
                 simulation. The default value is -1.-->
            <KeyDelay>-1</KeyDelay> <!-- Optional. -->

            <!-- Like 'EventDelay', but only influences mouse simulation and not keyboard
                 simulation. The default value is -1. -->
            <MouseDelay>-1</MouseDelay> <!-- Optional. -->

            <!-- Sets the maximum number of warnings to output. 0 for unlimited, defaults to 2000. -->
            <MaxWarnings>2000</MaxWarnings> <!-- Optional. -->

            <!-- Enables or disables the Windows Error Reporting dialog, which is disabled by
                 default. The default value is false. -->
            <NoCrashHandler>false</NoCrashHandler> <!-- Optional. -->

        </Commands>

    </QtTest>
</RunSettings>

另请参阅 教程:Qt Test 应用程序、使用 .runsettings 文件配置 Qt 测试,以及文件。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.