# 手动添加测试模块 test
扩展 -> qt vs tools -> qt project settings -> qt project settings -> general -> moudels# 手动添加测试模块 有报错
这个错误通常是由于缺少入口函数WinMain引起的。在使用Qt的测试框架时,可以通过定义一个特殊的宏来解决这个问题。
请按照以下步骤进行操作:
1. 打开您的测试项目的属性页。
2. 导航到“链接器 -> 系统”。
3. 将“子系统”设置为“Windows (/SUBSYSTEM:WINDOWS)”。
4. 导航到“链接器 -> 命令行”。
5. 在“附加选项”字段中添加以下内容:
```
/ENTRY:mainCRTStartup
```6. 重新编译和运行项目,看看是否解决了LNK2019和LNK1120错误。
这样做会将项目的入口点设置为mainCRTStartup,从而解决LNK2019和LNK1120错误。
# 测试结果 显示
********* Start testing of CalculatorTest *********
Config: Using QtTest library 5.14.2, Qt 5.14.2 (x86_64-little_endian-llp64 shared (dynamic) debug build; by MSVC 2017)
PASS : CalculatorTest::initTestCase()
PASS : CalculatorTest::testAddition()
PASS : CalculatorTest::testSubtraction()
PASS : CalculatorTest::cleanupTestCase()
Totals: 4 passed, 0 failed, 0 skipped, 0 blacklisted, 0ms
********* Finished testing of CalculatorTest *********# 测试结果 有报错的
********* Start testing of CalculatorTest *********
Config: Using QtTest library 5.14.2, Qt 5.14.2 (x86_64-little_endian-llp64 shared (dynamic) debug build; by MSVC 2017)
PASS : CalculatorTest::initTestCase()
FAIL! : CalculatorTest::testAddition() Compared values are not the same
Actual (result): 5
Expected (6) : 6
D:\360MoveData\Users\Administrator\Desktop\vs_utils\test_qtTest\test_qtTest\calculatortest.cpp(10) : failure location
PASS : CalculatorTest::testSubtraction()
PASS : CalculatorTest::cleanupTestCase()
Totals: 3 passed, 1 failed, 0 skipped, 0 blacklisted, 0ms
********* Finished testing of CalculatorTest *********