【问题标题】:Discovering Catch2 tests in Visual Studio when using CMake project使用 CMake 项目时在 Visual Studio 中发现 Catch2 测试
【发布时间】:2020-01-19 11:04:29
【问题描述】:

到目前为止,我一直在 Linux 上使用 CLion 开发我的项目,一切正常,但现在我正在尝试在 Windows 上设置我的项目以熟悉 Visual Studio IDE,但我无法获得 Visual Studio 来发现我的测试。

我在 Visual Studio 中直接使用 CMake 项目,构建、运行等工作正常,当我尝试使用编辑器中的 Run Test 选项运行单个测试时出现问题 - 测试资源管理器没看到。

我已经安装了Catch2 Test Adapter 并添加了所需的.runsettings,如here 所述,但即便如此,我在测试输出中看到的唯一内容是

No tests found to run.

有没有人尝试过类似的设置并可以指导我如何解决它?

我正在使用 Visual Studio 2019。

【问题讨论】:

    标签: visual-studio testing cmake try-catch


    【解决方案1】:

    好的,我通过生成 Visual Studio 解决方案并使用它而不是 CMake 项目来实现它,我的 .runsettings 看起来像这样:

    <?xml version="1.0" encoding="utf-8"?>
    <RunSettings>
      <!-- Configurations that affect the Test Framework -->
      <RunConfiguration>
        <MaxCpuCount>4</MaxCpuCount>
        <ResultsDirectory>.\TestResults</ResultsDirectory><!-- Path relative to solution directory -->
        <TestSessionTimeout>60000</TestSessionTimeout><!-- Milliseconds -->
      </RunConfiguration>
    
      <!-- Adapter Specific sections -->
    
      <!-- Catch2 adapter -->
      <Catch2Adapter disabled="false">
        <FilenameFilter>test</FilenameFilter>
        <WorkingDirectoryRoot>Solution</WorkingDirectoryRoot>
      </Catch2Adapter>
    
    </RunSettings>
    

    在Test Explorer > Configure Run Settings > Select Solution wide runsettings File中选择它

    【讨论】:

    • 如何解决?您最初的问题询问如何让测试资源管理器与 CMake 一起使用。似乎这个“答案”不是一个真正的答案,而是通过将 cmake 项目转换为 Visual Studio 解决方案的一种解决方法。
    猜你喜欢
    • 1970-01-01
    • 2019-08-09
    • 2013-05-30
    • 2020-03-25
    • 2020-01-16
    • 1970-01-01
    • 2018-09-11
    • 1970-01-01
    相关资源
    最近更新 更多