Google test is a great library that one can use for unit testing. Google mock is an extension of Google test as a mocking framework which can be used to mock the behavior of interfaces. First things first, build the library gmock. I use netbeans.
1. Create a new project as C/C++ static library
2. Include the files as "Add Existing Item" ${GTEST_DIR}/src/gtest-all.cc and ${GMOCK_DIR}/src/gmock-all.cc
3. Include the Directories and Headers for the compiler in project properties. ${GTEST_DIR}/include and ${GMOCK_DIR}/include and ${GTEST_DIR} and ${GMOCK_DIR}
4. Build.....
Note: It's mentioned that you need -pthread but since we are building a static library, the links are not resolved so you need to only enter them in the application linker properties.
Now you'll end up with the ".a file" in the dist folder.
Now create a new application as a C/C++ project. This project contains your application that should be tested or mocked using Google test framewrok.
You should include the above mentioned 4 folders in the C++ compiler path and includer the gtest library for the linker.
In a test application you create a new test folder under test files (see image) and create a new test file under that folder.
This test file will contain the Google test code grouped as different unit tests.
Now if you right click on "Test Files" and say "Test" the Google tests will be run and their status will be displayed as OK / PASSED or FAILED.
The Google test framework documentation is vast and I leave the discussion out on how to use the framework for testing and mocking.
1. Create a new project as C/C++ static library
2. Include the files as "Add Existing Item" ${GTEST_DIR}/src/gtest-all.cc and ${GMOCK_DIR}/src/gmock-all.cc
3. Include the Directories and Headers for the compiler in project properties. ${GTEST_DIR}/include and ${GMOCK_DIR}/include and ${GTEST_DIR} and ${GMOCK_DIR}
4. Build.....
Note: It's mentioned that you need -pthread but since we are building a static library, the links are not resolved so you need to only enter them in the application linker properties.
Now you'll end up with the ".a file" in the dist folder.
Now create a new application as a C/C++ project. This project contains your application that should be tested or mocked using Google test framewrok.
You should include the above mentioned 4 folders in the C++ compiler path and includer the gtest library for the linker.
In a test application you create a new test folder under test files (see image) and create a new test file under that folder.
This test file will contain the Google test code grouped as different unit tests.
Now if you right click on "Test Files" and say "Test" the Google tests will be run and their status will be displayed as OK / PASSED or FAILED.
The Google test framework documentation is vast and I leave the discussion out on how to use the framework for testing and mocking.
Comments
Post a Comment