googletest

Linking googleTest in VS2010 results in LNK2005 because of other dependent libraries

点点圈 提交于 2019-11-30 04:51:26
问题 I have a large and complicated project that is finally getting unit tests. I've built googleTest 1.6.0 locally with Visual Studio 2010, the project files built with cmake as the README specifies. This project has many dependent libraries that are statically and dynamically linked. Many of them proprietary. All attempts to link generate 220 such errors. Here is a sampling: msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: void __cdecl std::_Container_base12::_Orphan_all(void)" (?_Orphan

Teach Google-Test how to print Eigen Matrix

孤街浪徒 提交于 2019-11-30 03:53:26
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 precision. MATCHER_P2(EigenApproxEqual, expect, prec, std::string(negation ? "isn't" : "is") + " approx equal to" + ::testing::PrintToString(expect) + "\nwith precision " + ::testing::PrintToString(prec)) { return arg.isApprox(expect, prec); } What this does is to compare two Eigen matrices by their isApprox method , and if they don't match Google-Mock will print a

How to use googletest Failures into Break-Points

我与影子孤独终老i 提交于 2019-11-30 03:45:43
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 command line, I saw no effect (to be honest I had the glimpse of hope that VS2010 would be registered as debugger and somehow magically would pop up and point to the error source). Using it in the VS environment as command line argument a failed assertion triggered a break but the call stack did not include the test method that caused the failure. I

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

六眼飞鱼酱① 提交于 2019-11-30 03:31:44
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 int main() . The google test framework also uses macro definitions for each test. One of the problems is that it is not possible to call the wxWidgets macro from within the test macro, because the first one creates functions.. So, we found that we could replace the macro with the following code: wxApp* pApp = new MyApp(); wxApp::SetInstance(pApp);

What's the difference between gtest.lib and gtest_main.lib?

放肆的年华 提交于 2019-11-30 02:57:34
Google's C++ Test Framework has two output libraries: one is gtest.lib and the other one is gtest_main.lib. According to Nik Reiman's answer on how to setup gtest with Visual Studio , we should link to gtest_main.lib but I'm linking to gtest.lib and the sample test cases that I have are running fine. What's the difference between the two libraries and does it matter which one I link to? Andrey the only reasonable difference is that gtest_main.lib provides a default implementation of a test application entry point (i.e. main function): Citation from Getting started with Google C++ Testing

google-test: code coverage

点点圈 提交于 2019-11-30 02:56:26
Is it possible to get code coverage done by tests using google test framework? chalup Yes, I've successfully used both free (gcov) and commercial (CTC++) tools. No special steps are needed, just follow the documentation. More details can be found in this blog http://googletesting.blogspot.dk/2014/07/measuring-coverage-at-google.html Yes, You can club your Gtest Based application with support of Gcov/lcov. refer the documentation of lcov http://ltp.sourceforge.net/coverage/lcov.php there is one linux test project utility available which does your job very easy and is very self-interpretative.

How to compile googletest on windows using mingw with msys?

心已入冬 提交于 2019-11-30 02:17:44
My need is simple. I have to compile and use googletest on windows using MinGW with msys. Has anyone some experience doing this? Thanks for answers. Rusty Horse It took me some time but I figured it out. Here is the guide for anyone who face the same problem. To be able to compile GoogleTest on Windows follow this instructions: I assume you have MinGW with MSYS istalled. Download and install CMake from the official site http://www.cmake.org/ . Use the Win32 installer version. Once you have completed the installation process copy executable files from "xxx/CMake/bin" to "xxx/MinWG/bin".

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

荒凉一梦 提交于 2019-11-30 01:49:58
I have a test fixture class which is currently used by many tests. #include <gtest/gtest.h> class MyFixtureTest : public ::testing::Test { void SetUp() { ... } }; I would like to create a parameterized test which also uses all that MyFixtureTest has to offer, without needing to change all my existing tests. How do I do that? I have found similar discussions on the web, but have not fully understood their answers. The problem is that for regular tests your fixture has to be derived from testing::Test and for parameterized tests, it has to be derived from testing::TestWithParam<>. In order to

Is Google Test OK for testing C code?

眉间皱痕 提交于 2019-11-30 01:08:33
So I've come to like and enjoy using Google Test for a C++ project I'm involved in. I'm just bringing up a new project that will be straight C (a library) and so far can't see any reason why not to continuing using Google Test, even though its a C++ framework. Having a C++ compiler available will not be an issue. Are there are specific reasons why I shouldn't use Google Test for testing straight C code? Thanks. It is pretty common to test C code using a C++ testing frameworks, even the leading book on the subject follows this approach. I have used googletest extensively in the past to unit

Test a specific exception type is thrown AND the exception has the right properties

南楼画角 提交于 2019-11-29 23:12:08
I want to test that MyException is thrown in a certain case. EXPECT_THROW is good here. But I also want to check the exception has a specific state e.g e.msg() == "Cucumber overflow" . How is this best implemented in GTest? I mostly second Lilshieste's answer but would add that you also should verify that the wrong exception type is not thrown: #include <stdexcept> #include "gtest/gtest.h" struct foo { int bar(int i) { if (i > 100) { throw std::out_of_range("Out of range"); } return i; } }; TEST(foo_test,out_of_range) { foo f; try { f.bar(111); FAIL() << "Expected std::out_of_range"; } catch