【问题标题】:How do I run a custom C unit test with Appveyor?如何使用 Appveyor 运行自定义 C 单元测试?
【发布时间】:2025-12-12 05:55:02
【问题描述】:

我目前正在用 C (https://github.com/Srekel/sralloc) 编写一个开源库,并且正在运行一个简单的单元测试解决方案/项目。它使用一个简单的 C 单元测试框架并生成一个 unittest.exe 打印出结果并根据是否成功返回 1 或 0。

我的问题是我不确定如何配置 Appveyor 以在构建后运行此可执行文件。 Appveyor 可执行文件生成于C:\projects\sralloc\examples\Build\x64_Debug\unittest.exe

所以我尝试了这个:

test_script:
  - '%APPVEYOR_BUILD_FOLDER%\examples\build\%PLATFORM%_%CONFIGURATION%\unittest.exe'

但是 Appveyor 说:The system cannot find the path specified.

我在网上搜索了相当多的东西,但没有真正找到任何东西。

这是我的完整 appveyor.xml

version: 1.0.{build}

image: Visual Studio 2017

configuration:
 - Debug
 - Release

build:
  parallel: true
  project: examples/sralloc.sln

test_script:
  - '%APPVEYOR_BUILD_FOLDER%\examples\build\%PLATFORM%_%CONFIGURATION%\unittest.exe'

【问题讨论】:

    标签: c unit-testing appveyor


    【解决方案1】:

    我分叉了你的 repo 并将以下内容添加到你的appeyor.yml

    platform:
      - x64
    

    cannot find the path 错误消失了。如果您在 YAML 中没有此设置,则构建 VM 上没有名为 platform 的环境变量,并且 msbuild 正在选择 first in list 平台。

    旁注:现在它停留在Press any key to continue . . .,但我相信这是另一个主题,您可以通过更改命令行语法来修复它。

    附注 2:使用 this approach 上传文本结果(我假设您的测试可以在一种受支持的格式上创建 XML 结果。

    【讨论】:

      最近更新 更多