Google Test 未找到任何测试

问题描述 投票:0回答:4

所以我正在创建我的第一个单元测试。我正在使用 Google Test,该版本当前内置于 Visual Studio 2017 中。这是概念验证的尝试,非常简单。

我在测试代码的解决方案中有一个项目:test.cpp

#include "pch.h"
#include "../ConsoleApplication1/ConsoleApplication1.cpp"

TEST(SumTest, FirstTest) {
  EXPECT_EQ(6, sum(2, 4));
}

TEST(SumTest, SecondTest) {
    EXPECT_EQ(1, 1);
    EXPECT_TRUE(true);
}

我有一个简单的方法可以在 ConsoleApplication1.cpp 中进行测试

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

int sum(int a, int b);

int main()
{
    int x = sum(2, 4);
    printf("The answer is: %d \n", x);

}

int sum(int a, int b) {
    return a + b;
}

一切都编译得很好,但是当我从“测试资源管理器”菜单中单击“全部运行”时,我得到以下输出:

[5/7/2018 4:17:42 PM Informational] ------ Run test started ------
[5/7/2018 4:17:43 PM Informational] Test Adapter for Google Test: Test execution starting...
[5/7/2018 4:17:43 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:17:43 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe
[5/7/2018 4:17:43 PM Informational] Running 0 tests...
[5/7/2018 4:17:43 PM Informational] Google Test execution completed, overall duration: 00:00:00.3666448
[5/7/2018 4:17:43 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:17:44 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:17:44 PM Warning] No test is available in C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[5/7/2018 4:17:44 PM Informational] ========== Run test finished: 0 run (0:00:01.9324761) ==========
[5/7/2018 4:20:39 PM Informational] ------ Discover test started ------
[5/7/2018 4:20:40 PM Informational] Test Adapter for Google Test: Test discovery starting...
[5/7/2018 4:20:40 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:20:40 PM Informational] Test discovery completed, overall duration: 00:00:00.3954411
[5/7/2018 4:20:40 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:20:40 PM Informational] ========== Discover test finished: 0 found (0:00:01.8597435) ==========
[5/7/2018 4:20:47 PM Informational] ------ Discover test started ------
[5/7/2018 4:20:48 PM Informational] Test Adapter for Google Test: Test discovery starting...
[5/7/2018 4:20:49 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:20:49 PM Informational] Test discovery completed, overall duration: 00:00:00.3670275
[5/7/2018 4:20:49 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:20:49 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:20:49 PM Informational] ========== Discover test finished: 0 found (0:00:01.873206) ==========
[5/7/2018 4:21:36 PM Informational] ------ Run test started ------
[5/7/2018 4:21:37 PM Informational] Test Adapter for Google Test: Test execution starting...
[5/7/2018 4:21:38 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe
[5/7/2018 4:21:38 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:21:38 PM Informational] Running 0 tests...
[5/7/2018 4:21:38 PM Informational] Google Test execution completed, overall duration: 00:00:00.3844604
[5/7/2018 4:21:38 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:21:38 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:21:38 PM Warning] No test is available in C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[5/7/2018 4:21:38 PM Informational] ========== Run test finished: 0 run (0:00:02.0203611) ==========
[5/7/2018 4:27:21 PM Informational] ------ Run test started ------
[5/7/2018 4:27:34 PM Informational] Test Adapter for Google Test: Test execution starting...
[5/7/2018 4:27:35 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:27:35 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe
[5/7/2018 4:27:35 PM Informational] Running 0 tests...
[5/7/2018 4:27:35 PM Informational] Google Test execution completed, overall duration: 00:00:00.6936342
[5/7/2018 4:27:35 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:27:35 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:27:35 PM Warning] No test is available in C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[5/7/2018 4:27:35 PM Informational] ========== Run test finished: 0 run (0:00:14.3144745) ==========
[5/7/2018 4:27:59 PM Informational] ------ Run test started ------
[5/7/2018 4:28:11 PM Informational] Test Adapter for Google Test: Test execution starting...
[5/7/2018 4:28:11 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe
[5/7/2018 4:28:11 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:28:11 PM Informational] Running 0 tests...
[5/7/2018 4:28:11 PM Informational] Google Test execution completed, overall duration: 00:00:00.6451099
[5/7/2018 4:28:11 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:28:12 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:28:12 PM Warning] No test is available in C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[5/7/2018 4:28:12 PM Informational] ========== Run test finished: 0 run (0:00:12.9601734) ==========
[5/7/2018 4:29:59 PM Informational] ------ Run test started ------
[5/7/2018 4:30:59 PM Error] Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Failed to initialize client proxy: could not connect to test process.
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)
[5/7/2018 4:30:59 PM Error] Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Failed to initialize client proxy: could not connect to test process.
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)
[5/7/2018 4:30:59 PM Informational] ========== Run test finished: 0 run (0:01:00.2319577) ==========
[5/7/2018 4:34:34 PM Informational] ------ Discover test started ------
[5/7/2018 4:34:36 PM Informational] Test Adapter for Google Test: Test discovery starting...
[5/7/2018 4:34:36 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:34:36 PM Informational] Test discovery completed, overall duration: 00:00:00.3801077
[5/7/2018 4:34:36 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:34:36 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:34:36 PM Informational] ========== Discover test finished: 0 found (0:00:01.89196) ==========
[5/7/2018 4:34:41 PM Informational] ------ Run test started ------
[5/7/2018 4:34:42 PM Informational] Test Adapter for Google Test: Test execution starting...
[5/7/2018 4:34:43 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe
[5/7/2018 4:34:43 PM Informational] Found 0 tests in executable C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe
[5/7/2018 4:34:43 PM Informational] Running 0 tests...
[5/7/2018 4:34:43 PM Informational] Google Test execution completed, overall duration: 00:00:00.3975222
[5/7/2018 4:34:43 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:34:43 PM Warning] Could not locate debug symbols for 'C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe'. To make use of '--list_content' discovery, ensure that debug symbols are available or make use of '<ForceListContent>' via a .runsettings file.
[5/7/2018 4:34:43 PM Warning] No test is available in C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\ConsoleApplication1.exe C:\Users\ruggiero\source\repos\Google Test - Sandbox\Debug\Google Test - Sandbox.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[5/7/2018 4:34:43 PM Informational] ========== Run test finished: 0 run (0:00:01.9803681) ==========

它似乎没有发现我编写的任何一个测试,我不确定为什么。

c++ visual-studio-2017 googletest
4个回答
9
投票

常见情况下的 GoogleTest 框架 requires

RUN_ALL_TESTS
中的宏
main
:

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

然后您可以将测试添加到不同的

cpp
文件中,幕后的魔法将启动所有测试并显示漂亮的报告。

尽管如此,即使没有这个宏,您也可以使用 Google 测试。请参阅此答案


1
投票

我知道这个线程很旧,但我发现了导致此错误的另一个潜在原因。就我而言,测试 exe 文件无法加载 DLL,并且在未提供测试列表的情况下终止。我在项目设置中将测试单元的输出目录更改为与 DLL 相同,之后测试工作正常。


0
投票

@NuPagadi 他的答案是对的。如果之后仍然有问题,请使用正确的 google test nuget。我有相同的代码,我只是从 dyn.rt-dyn 切换到 static.rt-dyn 并测试资源管理器找到所有测试。


0
投票

RUN_ALL_TESTS()
中关于
main
的答案很接近,但不一定能准确指出预期的解决方案。
目前无需手动即可进行发现工作
main()

首先,在 Tools -> Options -> Test Adapter for Google Test -> General -> Print Debug Info 下启用调试可能很有用。

在那里有一个条目

Found X test method symbols and 0 trait symbols in binary

一个实际的问题是在 Linker -> Additional Dependency 中包含通配符 *\*.obj (目的是避免手动添加每个 .obj),它意外地将 obj 与引用项目中的 main() 一起使用,这以某种方式阻止了 Google 测试的预期主要内容。
删除多余的 *.obj 解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.