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
21
votes
4 answers

Teach Google-Test how to print Eigen Matrix

Introduction I am writing tests on Eigen matrices using Google's testing framework Google-Mock, as already discussed in another question. With the following code I was able to add a custom Matcher to match Eigen matrices to a given…
Lemming
  • 4,085
  • 3
  • 23
  • 36
21
votes
4 answers

How to mark a Google Test test-case as "expected to fail"?

I want to add a testcase for functionality not yet implemented and mark this test case as "it's ok that I fail". Is there a way to do this? EDIT: I want the test to be executed and the framework should verify it is failing as long as the testcase is…
zr.
  • 7,528
  • 11
  • 50
  • 84
20
votes
3 answers

How to setup googletest on Linux in the year 2012?

I am using Linux machine. I have download the googletest package from here However, there is no installation guide or other blogs related on how to set it up properly The README file is no good that I can't understand what it is talking about? Can…
TheOneTeam
  • 25,806
  • 45
  • 116
  • 158
20
votes
4 answers

How do I set up Google Test with a GNU Make project?

Since there's basically no documentation on the Google Test webpage—how do I do that? What I have done until now: I downloaded googletest 1.6 from the project page and did a ./configure && make inside it I added -Igtest/include -Lgtest/lib to my…
Daniel Ziltener
  • 647
  • 1
  • 6
  • 21
20
votes
1 answer

How do I disable a Googletest (gtest) parametrized test?

Googletest (GTest) allows you to disable individual tests by adding DISABLED_ prefix to the test name. What about parametrized tests -- how do I disable those? Adding the prefix to the test name does not disable them. For example, how do I disable…
Victor Lyuboslavsky
  • 9,882
  • 25
  • 87
  • 134
20
votes
3 answers

Customise actual/expected "Value of" string in Google Test failure output messages

I have the following output from a Google Test unit test: UnitTests.cc:56: Failure Value of: LineSegment2i(Vector2i(-10,0), Vector2i(-10,10)).toLine() Actual: 24-byte object <00-00 00-00 00-00 24-C0 00-00 00-00 00-00 00-00 00-00 2F-2B FF-7F…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
19
votes
1 answer

Disable exception handling while debugging c++ project using Google Test

I have my (native C++) DLL project and a corresponding test EXE project based on Google Test. While debugging my DLL via this EXE I have exceptions automatically handled by Google Test. So if my DLL throws an unhandled exception during debug, I…
Mikhail
  • 20,685
  • 7
  • 70
  • 146
19
votes
1 answer

How to use gmock MOCK_METHOD for overloaded operators?

I am new to googlemock (and StackOverflow). I got a problem when using MOCK_METHODn in googlemock and I believe this function is widely used. Here is what I did. I have an abstract class Foo with virtual overloaded operator[]: class Foo{ public: …
Ruoxi
  • 213
  • 1
  • 2
  • 6
19
votes
1 answer

Google Test - Test that a string does not contain a string

Using Google Test, I need a way to verify that a string that was returned by my class under test does not contain a particular string. I can currently test that a string does contain another string by using EXPECT_THAT and MatchesRegex; however, I…
Dustin Wilhelmi
  • 1,769
  • 2
  • 13
  • 27
19
votes
7 answers

How to test an EXE with Google Test?

I have a C++ project in Visual Studio, and have added another project exclusively for testing. Both of these projects are EXEs (console apps). So how do I use the first project inside the second? Just to clarify, the question here would be somewhat…
Dmitri Nesteruk
  • 23,067
  • 22
  • 97
  • 166
19
votes
1 answer

Can you test SetUp success/failure in Google Test?

Is there a way to check that SetUp code has actually worked properly in GTest fixtures, so that the whole fixture or test-application can be marked as failed rather than get weird test results and/or have to explicitly check this in each test?
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
19
votes
1 answer

GTest not finding tests in separate compilation units

I've got a program written in C++, with some subfolders containing libraries linked in. There's a top level SConscript, which calls SConscript files in the subfolders/libraries. Inside a library cpp, there is a GTest test function: TEST(X,…
Coran
  • 360
  • 3
  • 11
19
votes
2 answers

Unit Testing C++ Code in an Unnamed Namespace

I am working on a procedural C/C++ project. The public interface consists of 4 functions, each with fairly complex tasks. There are helper functions declared in the same cpp file, in an unnamed namespace. The test framework being used is…
user1599559
19
votes
3 answers

Establish gtest version

How do I know which version of Gtest is being used in the project I'm working with? I'm working on a linux platform.
Baz
  • 12,713
  • 38
  • 145
  • 268
19
votes
4 answers

How does google test make test sequence

How google-test makes test sequence (or order of test case execution) for testing test cases? Suppose I have 5 test cases. TEST(First, first) TEST(Secnd, secnd) TEST(Third, third) ... TEST(Fifth, fifth) How google-test test above test cases? I mean…
Rasmi Ranjan Nayak
  • 11,510
  • 29
  • 82
  • 122