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

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

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

How to start working with GTest and CMake

The solution involved putting the gtest source directory as a subdirectory of your project. I’ve included the working CMakeLists.txt below if it is helpful to anyone. cmake_minimum_required(VERSION 2.6) project(basic_test) ################################ # GTest ################################ ADD_SUBDIRECTORY (gtest-1.6.0) enable_testing() include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) ################################ # Unit Tests ################################ # Add test cpp file add_executable( runUnitTests testgtest.cpp ) # Link test … Read more

Comparison of C++ unit test frameworks [closed]

A new player is Google Test (also known as Google C++ Testing Framework) which is pretty nice though. #include <gtest/gtest.h> TEST(MyTestSuitName, MyTestCaseName) { int actual = 1; EXPECT_GT(actual, 0); EXPECT_EQ(1, actual) << “Should be equal to one”; } Main features: Portable Fatal and non-fatal assertions Easy assertions informative messages: ASSERT_EQ(5, Foo(i)) << ” where i … Read more

How to set up Google C++ Testing Framework (gtest) with Visual Studio 2005

(These instructions get the testing framework working for the Debug configuration. It should be pretty trivial to apply the same process to the Release configuration.) Get Google C++ Testing Framework Download the latest gtest framework Unzip to C:\gtest Build the Framework Libraries Open C:\gtest\msvc\gtest.sln in Visual Studio Set Configuration to “Debug” Build Solution Create and … Read more

CMake + GoogleTest

This is an unusual case; most projects specify install rules. CMake’s ExternalProject_Add module is maybe the best tool for this job. This allows you to download, configure and build gtest from within your project, and then link to the gtest libraries. I’ve tested the following CMakeLists.txt on Windows with Visual Studio 10 and 11, and … Read more