Reputation: 5712
I've an unmanaged mfc application. I would like to integrate some unit testing for that using gmock. I added all the includes, libraries.
But how can I start running tests?
I know they use main method to run test in other cases.
#include "gmock/gmock.h"
int main(int argc, char** argv) {
testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS();
}
but since mfc applications don't have main method but InitInstance method. How can I start running test?
Upvotes: 0
Views: 575
Reputation: 2754
Google recommends that you create a separate project for your tests - a test project - which has its own int main
. Their FAQs page references the following resource for guidance:
http://hassanjamilahmad.blogspot.com/2009/07/gtest-starters-help.html
(This makes sense, if you think about it. There's no real reason you should be deploying your unit tests in your final product. Unit tests are meant for developers' consumption; not your customers'.)
In a nutshell, here is the general setup:
int main
in this project, and add the googletest boilerplate code that you mentionedSome things to be wary of, based on past experience:
This setup requires classes/functions in your MFC project to be exported in order to be consumed by the test project (otherwise it has no way of accessing them)
We ran into some problems linking (i.e., via the linker) our MFC project to the test project. We ended up extracting code from the MFC project into separate libraries, and used googletest to test those libraries. (These were much easier to configure, and helped with code organization as a bonus.)
On Edit: To clarify, these details correspond to googletest but are also applicable to gmock, since gmock uses googletest under the hood.
Upvotes: 2