googletest

How to hide NVCC's “function was declared but never referenced” warnings?

与世无争的帅哥 提交于 2019-12-22 09:50:48
问题 When compiling CUDA programs which use Google Test, nvcc will emit false-positive warnings: function <name> was declared but never referenced An MCVE: // test.cu #include <gtest/gtest.h> namespace { __global__ void a_kernel() { printf("Works"); } TEST(ExampleTest, ExampleTestCase) { a_kernel<<<1, 1>>>(); } } Compiling it gives: $ nvcc test.cu -lgtest -lgtest_main test.cu(9): warning: function "<unnamed>::ExampleTest_ExampleTestCase_Test::ExampleTest_ExampleTestCase_Test()" was declared but

CMake and CTest's default “test” command skips a specially named test

怎甘沉沦 提交于 2019-12-22 09:48:59
问题 I'm using CTest with CMake to run some tests. I use the enable_testing() command which provides me with a default command for make test . All of the tests in my subdirectory are accounted for (by doing an add_test command) and make test works great, except one problem. There is a certain test, which I've named skip_test , that I do NOT want being run when I do make test . I would like to add a custom target so I can run make skip_test and it will run that test. I can do this by doing add

How to compile and link google tests in C++ project in Visual Studio 2013 but with Gtest installed by NuGet Package Manager?

我与影子孤独终老i 提交于 2019-12-22 06:42:17
问题 I have Microsoft Visual Studio 2013 Community Edition on Windows 7. I want to install gtest and gmock for C++ in newer way than downloading headers and binaries or compiling by myself. I found Tools > Nuget Package Manager > Manage Nugets Packages For Solution I chosen Online, then typed gtest. From search results I've found Google Test, so I've installed its for my current project. After the installation the code below compiles: #include <iostream> #include <gtest\gtest.h> using namespace

How to use gmock to test that a class calls it's base class' methods

◇◆丶佛笑我妖孽 提交于 2019-12-22 05:22:04
问题 class Foo { public: int x; int y; void move(void); }; class SuperFoo: public Foo { public: int age; void update(); }; SuperFoo::update(void) { move(); age++; } I'm just starting out with C++ and unit testing, I have some code resembling the above and I want to use gmock to test that SuperFoo::update() calls the base class' move() method. What would be that best way to attack this type of situation? 回答1: One way is to make the move method virtual, and create a mock of your class: #include

How to use google test for C++ to run through combinations of data

眉间皱痕 提交于 2019-12-21 09:06:32
问题 I have a unit test that I need to run for 200 possible combinations of data. (The production implementation has the data to be tested in configuration files. I know how to mock these values). I prefer nit writing separate test case for each combination and to use some way of looping through the data. Is there some such direct way using Google test for C++? Thanks, Karthick 回答1: You can make use of gtest's Value-parameterized tests for this. Using this in conjunction with the Combine(g1, g2, .

How to set $(OutDir), $(TargetName), $(TargetExt), and %(Lib.OutputFile) with Visual Studio?

梦想的初衷 提交于 2019-12-21 07:00:08
问题 I'm trying to build gtest on Visual Studio 2010. After converting the solution file, I tried to build, and I got the following warning messages. Warning 1 warning MSB8012: TargetPath(C:\Users\sucho\Desktop\gtest-1.5.0\msvc\gtest/Debug\gtest.lib) does not match the Library's OutputFile property value (C:\Users\sucho\Desktop\gtest-1.5.0\msvc\gtest\ Debug\gtestd.lib). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt

How to set $(OutDir), $(TargetName), $(TargetExt), and %(Lib.OutputFile) with Visual Studio?

萝らか妹 提交于 2019-12-21 07:00:05
问题 I'm trying to build gtest on Visual Studio 2010. After converting the solution file, I tried to build, and I got the following warning messages. Warning 1 warning MSB8012: TargetPath(C:\Users\sucho\Desktop\gtest-1.5.0\msvc\gtest/Debug\gtest.lib) does not match the Library's OutputFile property value (C:\Users\sucho\Desktop\gtest-1.5.0\msvc\gtest\ Debug\gtestd.lib). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt

Use Google Test from Qt in Windows

馋奶兔 提交于 2019-12-20 23:25:44
问题 I have a simple test file, TestMe.cpp: #include <gtest/gtest.h> TEST(MyTest, SomeTest) { EXPECT_EQ(1, 1); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } I have Google Test built as a static library. (I can provide the makefile if it's relevant.) I can compile TestMe.cpp from a command-line with no problem: g++ TestMe.cpp -IC:\gtest-1.5.0\gtest-1.5.0\include -L../gtest/staticlib -lgtest -o TestMe.exe It runs as expected. However, I cannot

SetUp vs Constructor in Test Fixture

送分小仙女□ 提交于 2019-12-20 16:19:15
问题 Why does a test fixture have a SetUp method in Google Test? Isn't the Constructor effectively the same thing? Likewise for the TearDown method. Calls to both SetUp and the Constructor, as well as TearDown and the Destructor, are consistent with the TestEventListeners: OnTestStart and OnTestEnd. 回答1: There is an answer to that in the FAQ: Should I use the constructor/destructor of the test fixture or the set-up/tear-down function? The first thing to remember is that googletest does not reuse

What is the difference between gtest and gmock?

北城以北 提交于 2019-12-20 10:21:54
问题 I'm trying to understand the purpose of google-mock , Google's C++ mocking framework. I have already worked with gtest earlier, but still I can't understand what gmock is. Why do we need it? gtest is used for unit testing. What do we need gmock for then, if gmock is required for unit testing ? 回答1: "Google Mock is not a testing framework itself. Instead, it needs a testing framework for writing tests. Google Mock works seamlessly with Google Test. It comes with a copy of Google Test bundled.