googletest

Building tests with CMake while not using CTest

霸气de小男生 提交于 2019-12-06 21:18:20
问题 Here is what I want to do: Typing make all will build my library and the docs for it. Typing make test will build my lib (if necessary), gtest and then my tests Typing make check runs make test if needed and then runs the executable Right now I've only managed to get the first to work. The problem I'm having is the conditional include of gtest. Gtest uses CMake which is nice, in theory all I need to do is to include the gtest directory with add_subdirectory but then gtest will always be built

Specify constructor arguments for a Google test Fixture

末鹿安然 提交于 2019-12-06 20:10:50
问题 With Google test I want to specify a Test fixture for use in different test cases. The fixture shall allocate and deallocate objects of the class TheClass and its data management class TheClassData , where the data management class requires the name of a datafile. For the different tests, the file name should vary. I defined the following Fixture: class TheClassTest : public ::testing::Test { protected: TheClassTest(std::string filename) : datafile(filename) {} virtual ~TheClassTest() {}

Linker error - linking two “application” type projects in order to use Google Test

落花浮王杯 提交于 2019-12-06 13:30:35
I am trying to test a function with Google Test. It seems that everything is set up correctly, and it builds and executes fine without gtest... (There is a bit of complexity in the code, so I cannot list all the source files here, but without adding gtest, the files are linking properly, and running as they should). It is an application type project. It has a number of library dependencies... irrelevant. The test project is added as a separate project to the solution. It has the tested project as a dependency. The .h file of the test project only points to the gtest... The .cpp (not main,

Can googlemock mock method calls from within other method calls of the same class?

断了今生、忘了曾经 提交于 2019-12-06 09:42:10
Is it possible to mock method calls from within other method calls of the same class? I am new to C++ (primarily a C developer) and very new to googlemock and Google Test so forgive me if this is answered elsewhere and I didn't understand the answer! Below is a simple example that should explain what I want to do. Using the example below, I want to mock ReturnInput , while testing ReturnInputPlus1 . using ::testing::Invoke; using ::testing::_; using ::testing::Return; class MyClass { public: MyClass() : x(1) {} virtual ~MyClass() {} int ReturnInput(int x) { return x; } int ReturnInputPlus1(int

gtest: Undefined symbols for architecture x86_64 error with clang++ and std::vector

陌路散爱 提交于 2019-12-06 04:44:54
问题 I downloaded the gtest 1.6, and compiled it with clang++. export CC=/usr/bin/clang export CXX=/usr/bin/clang++ configure make I got the libgtest.a, and I copied it into /usr/local/lib/libgtest_clang.a . When I tested with simple C++ code, everything works OK, however, when I tried to use vector in test code, I got these error messages in the build process. Compilation works fine. Undefined symbols for architecture x86_64: "std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator

Why is Google Test segfaulting?

无人久伴 提交于 2019-12-06 01:23:55
I'm new to Google Test and I'm playing around with the provided examples. My issue is, when I introduce a failure and set GTEST_BREAK_ON_FAILURE=1 (or use the command line option), GTest will segfault. I am considering this example . If I insert something like this into any of the tests, I will start to get the segfault: EXPECT_EQ(8, 2*3); Just to reiterate, that is only when I have also set GTEST_BREAK_ON_FAILURE=1 . I have run from the command line and also with gdb. If that environment variable is not set, it reports the error but does not segfault. Any clue to what could be causing this

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

孤人 提交于 2019-12-05 23:34:33
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_custom_target(skip_test ...) and providing CTest with the -R flag and telling it to look for files

Google Test: error LNK2019: unresolved external symbol with Visual Studio 2013

天大地大妈咪最大 提交于 2019-12-05 22:06:52
I'm trying to get my first ever unit test with Google Test framework + Visual Studio 2013.However I'm hitting the below error and can't understand why. 1>------ Build started: Project: FirstGoogleTest, Configuration: Debug Win32 ------ 2>------ Build started: Project: googleTest, Configuration: Debug Win32 ------ 1> MyMultiplier.cpp 2> gtest_main.cc 1> main.cpp 1> Generating Code... 2> gtest-all.cc 1> FirstGoogleTest.vcxproj -> D:_Vault\Workspaces\UnitTestLearning\FirstGoogleTest\Debug\FirstGoogleTest.exe 2> Generating Code... 2> googleTest.vcxproj -> D:_Vault\Workspaces\UnitTestLearning

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

久未见 提交于 2019-12-05 21:04:33
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 never referenced This is confirmed with the master branch of google test and CUDA 9.1 (I believe it

Custom EXPECT_NEAR macro in Google Test

跟風遠走 提交于 2019-12-05 19:04:25
Scope: Using Google Test and OpenCV. I'd like to test that my Vec3f equals another Vec3f . Vec3f is a vector in OpenCV of dimension 3 and type float. The ==-operator is defined, so EXPECT_EQ(Vec3f(), Vec3f()) works. But as they are floats, I'd like to use the EXPECT_NEAR(float a, float b, float delta) macro. What can I do so that I can use it like EXPECT_NEAR(vec_a, vec_b, float delta) ? At the moment I am looping through each element of the vector and doing an EXPECT_NEAR there. This might be related: Convenient method in GoogleTest for a double comparison of not equal? You are doing