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
11
votes
1 answer

Data-driven unit tests with google test

I am currently writing unit tests for an embedded application using googles unit test framework. Now my boss got upset that the data I test with (i.e. the values with which I call methods of the class under test) is hard wired in the tests. He…
sigy
  • 2,408
  • 1
  • 24
  • 55
11
votes
1 answer

CTest --build-and-test with --test-command option

I use Ctest to run a bunch of google tests that I have registered using add_test(). Currently, these tests do not take any arguments. However, I want to give them all arguments (common to all, specifically --gtest_output=xml) while running ctest. I…
nirvanaswap
  • 859
  • 2
  • 11
  • 21
11
votes
1 answer

Get google test exception throw message

I am using google Test framework for my project. I am throwing exception from the code as: throw DerivedClassException("message"); and in the test frame using as: ASSERT_THROW(commond(), DerivedClassException); I want to get message with…
anurudh
  • 338
  • 1
  • 4
  • 15
11
votes
5 answers

GoogleTest and Memory Leaks

I'm surprised that Google C++ Testing Framework does not explicitly support checking for memory leaks. There is, however, a workaround for Microsoft Visual C++, but what about Linux? If memory management is crucial for me, is it better to use…
Andrew
  • 197
  • 2
  • 3
  • 16
11
votes
3 answers

GoogleTest test error print of enum class

I'm using GoogleTest version 1.7.0 to test my C++ application. I have an enum defined as following namespace MyNamespace { enum class MyEnum { MyEnumValue, MyEnumValue2 } } GoogleTest incorrectly prints it's value, resulting…
Stefano
  • 3,213
  • 9
  • 60
  • 101
11
votes
2 answers

Is there a gtest equivalent for fixture-level setup/teardown?

So, I know there's "literally" fixtures for gtest, but the constructor/destructor and setup/teardown functions will execute after each test rather than after the entire set of tests in the fixture. I can think of ways of hacking around this, but is…
user3338893
  • 917
  • 3
  • 10
  • 17
11
votes
5 answers

Google Test: error LNK2019: unresolved external symbol with Visual Studio 2013

I'm trying to get my first ever unit test with Google Test framework + Visual Studio 2013.However I'm hitting the below error and can't understand why. 1>------ Build started: Project: FirstGoogleTest, Configuration: Debug Win32 ------ 2>------…
Solti
  • 633
  • 2
  • 6
  • 17
11
votes
2 answers

Why doesn't compiler recognize members of my type-parameterized test fixture class?

I'm writing a type-parameterized test fixture using gtest, and I'm seeing a not declared in this scope compiler error when I try to use members from the fixture class. When I'm not using a type-parameterized fixture, I can access class members just…
Ziv
  • 2,369
  • 3
  • 24
  • 40
11
votes
3 answers

How to properly setup googleTest on OS X aside from XCode

How do I setup gTest, so that I can link aganist the library? I will code in vim, so I just want to install the libraries, unlike the XCode setup. Goal is to be able to link a project against the library by setting -lgtest as linker flag and…
ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103
11
votes
1 answer

Linking to multiple .obj for unit testing a console application

Having a few issues and hope I can find some help. I have two projects under the same solution in Visual Studio 2012 A bit of background I cam creating a console application which outputs as a .exe this is in one project. In another project I have…
Chris Crew
  • 353
  • 4
  • 15
11
votes
2 answers

How can I instantiate an object of class Foo for Ts listed in MyTypes in a test?

I want to test a template class with gtest. I read about TYPED_TESTs in Google Test manual and looked at official example they reference, but still can't wrap my head around getting an object of template class instantiated in my test. Suppose the…
Puchatek
  • 1,477
  • 3
  • 15
  • 33
11
votes
1 answer

Is it safe to link to a static library built with different compiler flags

I use GoogleTest for testing my C++ projects, and after finding that precompiled libraries were no longer distributed in the Ubuntu package, I found the following on the project website: If you compile Google Test and your test code using different…
user360907
11
votes
2 answers

Grouping googletest unit tests by categories

Can googletest unit tests be grouped by categories? For example "SlowRunning", "BugRegression", etc. The closest thing I have found is the --gtest_filter option. By appending/prepending category names to the test or fixture names I can simulate…
walrii
  • 3,472
  • 2
  • 28
  • 47
10
votes
3 answers

Can I pass parameters to googletest test function

After building my testfile, xxxxtest, with gtest can I pass a parameter when running the test, e.g. ./xxxxtest 100. I want to control my test function using the parameter, but I do not know how to use the para in my test, can you show me a sample in…
gino
  • 165
  • 1
  • 2
  • 10
10
votes
1 answer

With CMake, how can I set environment properties on the gtest_discover_tests --gtest_list_tests call?

I'm currently working on migrating our current build environment from MSBuild to CMake. I have a situation where I need to update the PATH variable in order for the units tests executable to run. This is not a issue for gtest_add_tests, as it uses…
travis
  • 233
  • 3
  • 11