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
30
votes
6 answers

Using gtest in jenkins

I successfully run my unit test with google test in Jenkins, but I don't know how to show the .xml file generated by gtest. It is said that gtest satisfies the JUnit format, so what I set is as follows: But it ends up with errors after a…
venus.w
  • 2,171
  • 7
  • 28
  • 42
29
votes
3 answers

Can I give better names to value-parameterized tests in gtest?

I use value-parameterized tests in gtest. For example, if I write INSTANTIATE_TEST_CASE_P(InstantiationName, FooTest, ::testing::Values("meeny", "miny", "moe")); then in the output I see test names such…
Lev
  • 6,487
  • 6
  • 28
  • 29
28
votes
7 answers

Expect a value within a given range using Google Test

I want to specify an expectation that a value is between an upper and lower bound, inclusively. Google Test provides LT,LE,GT,GE, but no way of testing a range that I can see. You could use EXPECT_NEAR and juggle the operands, but in many cases this…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
28
votes
6 answers

wxWidgets: How to initialize wxApp without using macros and without entering the main application loop?

We need to write unit tests for a wxWidgets application using Google Test Framework. The problem is that wxWidgets uses the macro IMPLEMENT_APP(MyApp) to initialize and enter the application main loop. This macro creates several functions including…
m_pGladiator
  • 8,462
  • 7
  • 43
  • 61
28
votes
3 answers

Gtest: Undefined References

I am trying to use GoogleTest to test a simple function, but as I run make in my build folder, the compiler throws Undefined Reference error messages at me. I've referenced the gtest header file, so I'm not sure what is wrong. Any ideas? I'm new to…
Vance
  • 471
  • 4
  • 8
  • 16
27
votes
2 answers

Simplest example of using Google C++ Testing Framework with CMake

I have a very simple C++ library (one header file, one .cpp file). I want to write unit tests for this project using the Google C++ Testing Framework. Here is the directory structure: ~/project1 | |-- project1.cpp |-- project1.h |--…
Agnel Kurian
  • 57,975
  • 43
  • 146
  • 217
27
votes
1 answer

How to use googletest Failures into Break-Points

I recently discovered the Failures into Break-Points - option from googletest using the command line option gtest_break_on_failure or by defining the GTEST_BREAK_ON_FAILURE environment variable. I gave it a try using gtest_break_on_failure. From…
anhoppe
  • 4,287
  • 3
  • 46
  • 58
26
votes
3 answers

Google Mock unit testing static methods c++

I just started working on unit testing (using BOOST framework for testing, but for mocks I have to use Google Mock) and I have this situation : class A { static int Method1(int a, int b){return a+b;} }; class B { static int Method2(int a, int b){…
Jonhtra
  • 897
  • 2
  • 12
  • 18
26
votes
3 answers

How can I use Google Test with my project that builds via autotools?

It seems like there are a few answers that kind-of, sort-of make sense, but that I don't know how to carry out. And I haven't found a comprehensive answer. The First Problem Google Test should not be an installed library, it should be built with the…
Joel
  • 2,065
  • 2
  • 19
  • 30
26
votes
7 answers

Can gmock be used for stubbing C functions?

I am new to gmock, so I want to know how can I stub simple C function called in a function under test for Unit Testing. Example: int func(int a) { boolean find; // Some code find = func_1(); return find; } I have searched about gmock and in…
SRehman
  • 389
  • 1
  • 3
  • 7
26
votes
3 answers

Google Test: Parameterized tests which use an existing test fixture class?

I have a test fixture class which is currently used by many tests. #include class MyFixtureTest : public ::testing::Test { void SetUp() { ... } }; I would like to create a parameterized test which also uses all that MyFixtureTest…
des4maisons
  • 1,791
  • 4
  • 20
  • 23
26
votes
8 answers

Is there a graphical test runner for "Google Test" ( gtest ) for windows?

Seems a great C++ unit testing framework. I'm just wanting something a bit more sophisticated than the console output for running the test, also something that makes it really easy to run specific tests (since gtest supports all kinds of test…
Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
25
votes
2 answers

Can Googletest value-parameterized with multiple, different types of parameters match mbUnit flexibility?

I'd like to write C++ Google tests which can use value-parameterized tests with multiple parameters of different data types, ideally matching the complexity of the following mbUnit tests written in C++/CLI. For an explanation of mbUnit, see the…
Andy Dent
  • 17,578
  • 6
  • 88
  • 115
25
votes
5 answers

Compare ptr with nullptr in gtest

Have some code: EXPECT_NE(nullptr,ptr); And I get the following compilation error: 'operator <<' is ambiguous could be 'std::basic_ostream> &std::basic_ostream>::operator…
Igor Pugachev
  • 604
  • 1
  • 5
  • 14
25
votes
6 answers

Specify constructor arguments for a Google test Fixture

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…
Gregor
  • 411
  • 1
  • 6
  • 12