GoogleTest: How to skip a test?

The docs for Google Test 1.7 suggest: If you have a broken test that you cannot fix right away, you can add the DISABLED_ prefix to its name. This will exclude it from execution. This is better than commenting out the code or using #if 0, as disabled tests are still compiled (and thus won’t … Read more

How to test an EXE with Google Test?

Per your comments, you have a C++ console application (MyApp) for which you have developed some application-specific classes that you want to unit-test with googletest in Visual Studio. How? As you say, if you wanted to unit-test a library the way to do it would be obvious. You would: 1) Create a project to create … Read more

Comparison of arrays in google test?

I would really suggest looking at Google C++ Mocking Framework. Even if you don’t want to mock anything, it allows you to write rather complicated assertions with ease. For example //checks that vector v is {5, 10, 15} ASSERT_THAT(v, ElementsAre(5, 10, 15)); //checks that map m only have elements 1 => 10, 2 => 20 … Read more

google mock – can I call EXPECT_CALL multiple times on same mock object?

Yes, you can call EXPECT_CALL on the same mock object multiple times. As long as you assure that all EXPECT_CALL were called before the mocked methods were actually used. Otherwise your test will rely on undefined behavior. From ForDummies: Important note: gMock requires expectations to be set before the mock functions are called, otherwise the … Read more

CMake Error: “add_subdirectory not given a binary directory”

The error message is clear – you should also specify build directory for googletest. # This will build googletest under build/ subdirectory in the project’s build tree add_subdirectory( ${GOOGLETEST_PROJECT_LOCATION} build) When you give relative path (as a source directory) to add_subdirectory call, CMake automatically uses the same relative path for the build directory. But in … Read more

CPack: Exclude INSTALL commands from subdirectory (googletest directory)

So there is the macro option @Tsyvarev mentioned that was originally suggested here: # overwrite install() command with a dummy macro that is a nop macro (install) endmacro () # configure build system for external libraries add_subdirectory(external) # replace install macro by one which simply invokes the CMake install() function with the given arguments macro … Read more

How to set up googleTest as a shared library on Linux

Before you start make sure your have read and understood this note from Google! This tutorial makes using gtest easy, but may introduce nasty bugs. 1. Get the googletest framework wget https://github.com/google/googletest/archive/release-1.8.0.tar.gz Or get it by hand. I won’t maintain this little How-to, so if you stumbled upon it and the links are outdated, feel … Read more