c++ Google Test未找到任何测试

pes8fvy9  于 12个月前  发布在  Go
关注(0)|答案(4)|浏览(99)

所以我正在创建我的第一个单元测试。我正在使用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) ==========

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

jm2pwxwz

jm2pwxwz1#

GoogleTest框架在main中的常见情况requiresRUN_ALL_TESTS宏:

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

然后你可以将你的测试添加到不同的cpp文件中,引擎盖下的魔法将启动所有这些文件并显示漂亮的报告。
即使没有这个宏,你也可以使用Google Tests。看看这个answer

b1zrtrql

b1zrtrql2#

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

v2g6jxz6

v2g6jxz63#

@NuPagadi有权利与他的answer。如果你在这之后仍然有问题,使用正确的谷歌测试掘金。我有相同的代码,我只是从dyn.rt-dyn切换到static.rt-dyn和测试资源管理器找到所有测试。

lndjwyie

lndjwyie4#

关于main()RUN_ALL_TESTS()的答案很接近,但还有细节。当前发现在没有手动主电源的情况下工作。
值得注意的是,设置Project Configuration-> Referenced Packages -> Google test -> Use Google Test's main Function 应该会自动提供main。
在 * 工具 * ->选项-> * 测试适配器Google测试 * -> * 常规 * -> * 打印测试信息 * 下启用调试可能会很有用。
启用后,日志中有其他条目:

Found 4 test method symbols and 0 trait symbols in binary  ...  
Found 0 tests in executable ...  
Test discovery completed ...  
No test is available in ...

一个实际的问题是在 Additional addictions * 中包含了.obj**.obj**(目的是避免手动添加每个.obj)。这还包括引用项目中带有main()的obj,它以某种方式取代了GT替代方案。
删除过多的 *.obj**解决了这个问题。

相关问题