问题描述
我使用CxxTest进行单元测试。我跟着文档。
I am using CxxTest for unit testing. I followed the docs.
我执行的第一个命令是:
First command I executed was:
cxxtestgen --error-printer -o runner.cpp MyTestSuite1.h
命令的输出为 .cpp
文件。
根据文档,下一个命令应该是:
According to the documentation, next command should be:
g++ -o runner -I(location_of_the_cxxTest_headers) runner.cpp
但我无法执行它,我收到关于缺少入口点的错误。换句话说, runner.cpp
缺少main。
but I am unable to execute it, I am receiving the error about missing entry point. In other words, runner.cpp
is missing main.
CxxTest包含的测试文件也会发生同样的情况。
Same thing happens with the test files included with CxxTest.
我正在运行Windows 8.1。
I am running Windows 8.1.
我的问题被标记为重复,但我没有找到解决方案在另一个问题。我不是构建一个GUI应用程序。问题是关于CxxTest,它甚至开始没有 main()
函数?
My question is marked as a duplicate, but I didn't find solution in the another question. I am not building a GUI application. Question is about CxxTest and how does it even start without a main()
function? Where is the entry point?
推荐答案
我在查看python脚本 cxxtestgen后发现了一个解决方案。 py
,用于生成 runner.cpp
。在 writeMain(output)
函数的开头有一个if语句,它在输出文件中写入 main
I have found a solution after looking at a python script cxxtestgen.py
which is used to generate runner.cpp
. There is an if statement at the beginning of a writeMain(output)
function which writes main
function in an output file:
if not (options.gui or options.runner):
return
两个选项中至少有一个 - runner = CLASS
和<$ c从测试套件生成输出文件时,需要$ c> - gui = CLASS 。添加一个选项后,一切运行良好。
At least one of the two options, --runner=CLASS
and --gui=CLASS
is required when generating output file from test suites. After adding one option everything runs fine.
这篇关于CxxTest编译,缺少主的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!