What is the difference between gmock_main and gtest_main?
Asked Answered
V

1

6

I've noticed that some projects refer to gtest_main-mdd.lib and others to gmock_maind.lib in my Visual Studio 2010 setup and wanted to know what the difference between the two libs is?

Verbena answered 26/6, 2015 at 5:14 Comment(2)
Refer to this link - #13696876Certainly
@Certainly Perhaps I wasn't clear. I understand the difference between the two frameworks but what I want to know is why I would want to link to one over the other? Or more simply, is gmock_maind.lib a superset of gtest_main-mdd.lib's functionality?Verbena
G
9

Projects don't have to use both gtest and gmock but one might want to choose using gtest without gmock or vice versa. For either case you need a way to introduce the main function, hence you have 2 libs for introducing it.

Anyway, if you are using both then it's better to use gmock_maind.lib since it has an initialization for the mock framework and for the test framework as well. While gtest_main-mdd.lib initializes only the test part. Look at the gmock_main.cc and gtest_main.cc

Goatherd answered 26/6, 2015 at 5:56 Comment(2)
So does that mean that gmock_maind.lib assumes you're using it along-side gtest? If not and you do link against both how can you have two main functions? Is it done in the linker via weak symbols or what?Verbena
@nonsensickle, both these libs are just for the initialization. You may not use them at all, you can create your own main and add the required initialization yourself. But once you used either of the libs you have the main function from that lib. It is only one main function in each lib so you can't use both libs simultaneously but only one at a time. Gmock's one knows about gtest and calls init functions for it where Gtest's one doesn't know anything about gmock and hence doesn't initialize it.Goatherd

© 2022 - 2024 — McMap. All rights reserved.