Questions tagged [googletest]

Google's C++ testing framework based on xUnit that runs on multiple platforms.

GoogleTest is an open source unit testing framework developed by Google. It also supports unit testing of C code.

GTest (as it is commonly known) supports various platforms including Linux, OS X, Windows and Symbian. It provides basic unit testing features in the xUnit model in the form ASSERT_EQ() or EXPECT_EQ(), with automatic test registration. It also provides advanced features such as death tests, shuffling and sharding of tests, and Hudson/Jenkins-compatible XML output.

GTest integrates well with gmock, a C++ mocking framework.

There are three GTest related open source projects which can enhance the GTest user experience:

  1. Google Test UI - provides a GUI for running gtest binary and displaying the results.
  2. GTest TAP listener - Event listener for GTest based on TAP, for test result output.
  3. gtpp - Google Test Pretty Printer, offering shorter and clearer console test output
2773 questions
12
votes
3 answers

How to test multi-parameter formula

I'm refactoring some code that implements a formula and I want to do it test-first, to improve my testing skills, and leave the code covered. This particular piece of code is a formula that takes 3 parameters and returns a value. I even have some…
MikMik
  • 3,426
  • 2
  • 23
  • 41
12
votes
2 answers

Does Mock Objects in C++ Always Requires Virtual Methods or Templates?

Suppose I have classes class Inner { public: void doSomething(); }; class Outer { public: Outer(Inner *inner); // Dependency injection. void callInner(); }; Proper unit-testing says I should have tests for Inner. Then, I should…
kirakun
  • 2,770
  • 1
  • 25
  • 41
12
votes
6 answers

Viewing Google Test results within Visual Studio

Is there a way to view Google Test results within Visual Studio? If yes, how? I'm using Google Test 1.5.0 and Visual Studio 2010 Until now I've been using Google Test from the command line. I've seen such integrations on other IDEs (eclipse...) but…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
12
votes
2 answers

GoogleTest for Android NDK C++ with CMake

How do I setup GoogleTest for my native C++ code on Android with CMake? The Android NDK comes bundled with googletest but instructions are available only for Android.mk (here). How do I port the Android.mk gtest setup to my CMakeLists.txt? And once…
user740857
  • 475
  • 4
  • 11
12
votes
1 answer

How to use googletest for testing C++ code that calls into java on android?

I am working on a rather complicated C++ library that I plan to test properly using googletest for Android NDK. So far I follow the google test example and structure the project like this: Android.mk: LOCAL_PATH := $(call my-dir) include…
Luz
  • 494
  • 3
  • 12
12
votes
3 answers

How to write unit test for network client?

I need to write simple http client. It could be great to have unit tests for my class. But I don't know how to write proper and testable class. For example, I have a client like this: class HTTPClient { public: HTTPCLient(const std::string&…
peter55555
  • 1,413
  • 1
  • 19
  • 36
12
votes
3 answers

CPack: Exclude INSTALL commands from subdirectory (googletest directory)

I'm using CMake for a project and googletest for my test cases. Looking around the internet, it seems to be common practise to just copy the googletest source into a subfolder of your repository and include it with "add_subdirectory(googletest)". I…
Heinzi
  • 5,793
  • 4
  • 40
  • 69
12
votes
2 answers

How strict is the rule of no-underscores in TEST() names?

The document of Google Test says: TEST() arguments go from general to specific. The first argument is the name of the test case, and the second argument is the test's name within the test case. Both names must be valid C++ identifiers, and they…
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
12
votes
2 answers

How to get a custom operator== to work with Google Test?

I'm having trouble using a custom overloaded '==' operator with PCL and Google Test (GTest) #include namespace pcl { struct PointXYZ; } bool operator==(pcl::PointXYZ p1, pcl::PointXYZ p2) {return p1.x-p2.x<.1;} #include…
Andrew Wagner
  • 22,677
  • 21
  • 86
  • 100
12
votes
1 answer

How to initialize constant string for multiple tests in google test?

I'm using google test and I have a cpp-file containing several tests. I would like to initialize a string with the current date and time when starting the first test. I would like to use this string in all other tests, too. How can I do this. I've…
Semjon Mössinger
  • 1,798
  • 3
  • 22
  • 32
12
votes
1 answer

Google Mock: why NiceMock does not ignore unexpected calls?

I am using Google Mock 1.7.0 with Google Test 1.7.0. The problem is when I use NiceMock I get test failures because of unexpected mock function call (which should be ignored by NiceMock as per Google Mock documentation). The code looks like this: //…
Uniqus
  • 564
  • 1
  • 5
  • 21
12
votes
3 answers

ASSERT_TRUE() return type does not match function type in gtest

When I am using ASSERT_TRUE() provided in Gtest I am getting below error. return type does not match function type with an underline in VS 2010.. abc.h #include "gtest\gtest.h" class abc { pubilc: bool fun(); private: bool…
Rasmi Ranjan Nayak
  • 11,510
  • 29
  • 82
  • 122
11
votes
3 answers

Is data-driven testing bad?

I've started using googletest to implement tests and stumbled across this quote in the documentation regarding value-parameterized tests You want to test your code over various inputs (a.k.a. data-driven testing). This feature is easy to abuse,…
bbtrb
  • 4,065
  • 2
  • 25
  • 30
11
votes
1 answer

How to stop GTest test-case execution, when first test failed

I'm looking for some #define which can stop test-case execution if first test failed TEST_F(TestInitializer, 1st-test) { Initiator.call(); EXPECT_CALL(mock_obj, onAction(false)).Times(AtLeast(0)); // some define I want …
Yuriy Gyerts
  • 1,464
  • 18
  • 30
11
votes
1 answer

How to use Jenkins declarative pipeline to build and test on multiple platforms

I'm trying to do something that I feel should be simple to do, but I can't figure out how. Basically I have a Jenkins master (running on Linux) and two slaves, one on Windows and the other on macOS. I want to build my project on all 3 platforms and…