Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between gtest and gmock?

I'm trying to understand the purpose of google-mock, Google's C++ mocking framework.

I have already worked with gtest earlier, but still I can't understand what gmock is. Why do we need it?

gtest is used for unit testing. What do we need gmock for then, if gmock is required for unit testing?

like image 622
Rasmi Ranjan Nayak Avatar asked Dec 04 '12 05:12

Rasmi Ranjan Nayak


People also ask

Is Gmock part of Gtest?

GoogleMock is a part of GoogleTest C++ testing framework and a subject to the same requirements.

What is Gtest?

Google Test (also known as gtest) is a unit testing library for the C++ programming language, based on the xUnit architecture. The library is released under the BSD 3-clause license.

What is Mock_method?

Mocking Private or Protected Methods You must always put a mock method definition ( MOCK_METHOD ) in a public: section of the mock class, regardless of the method being mocked being public , protected , or private in the base class.

Can I use Gtest for C?

GTest is objected oriented tool and C language isn't! from GTest website gmock_for_dummies.md so you will use only macros like expect_equal, expect_bigger_than and so on... I would like to suggest you tool CMocka (or some other C unit testing tools).


2 Answers

"Google Mock is not a testing framework itself. Instead, it needs a testing framework for writing tests. Google Mock works seamlessly with Google Test. It comes with a copy of Google Test bundled. Starting with version 1.1.0, you can also use it with any C++ testing framework of your choice. " - Google Mock, System Requirements

Mock are like objects, defined in such a way to mimick the real-deal by supplying controlled behavior. For instance, to test a stock tick application, you'd create a fake stock data provider that created fake stock quotes to test your code with. Think of the word mock, literally means 'to mimic'.

like image 127
dans3itz Avatar answered Oct 26 '22 18:10

dans3itz


Software units do not live in green meadows. They very often need some counterparts to do the work. In real system, these counterparts belong to the system itself. In the unit tests they are replaced with mocks.

Gtest is a framework for unit testing. Gmock is a framework imitating the rest of your system during unit tests.

like image 38
Thinkeye Avatar answered Oct 26 '22 19:10

Thinkeye