Skip to content

Instantly share code, notes, and snippets.

@alanduan
Last active September 4, 2016 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanduan/6ab560575e3fb1cfd7ec8392e123cb68 to your computer and use it in GitHub Desktop.
Save alanduan/6ab560575e3fb1cfd7ec8392e123cb68 to your computer and use it in GitHub Desktop.
Google Mock & Boost Test, support static lib and dynamic lib
#define BOOST_TEST_MODULE Demo Boost Test & GMock
#include <boost/test/unit_test.hpp>
#include <gmock/gmock.h>
class HookupListner : public ::testing::EmptyTestEventListener
{
public:
void OnTestPartResult(const ::testing::TestPartResult& result)
{
boost::unit_test::unit_test_log
<< boost::unit_test::log::begin(result.file_name(), result.line_number())
<< boost::unit_test::log_all_errors
<< result.summary()
<< boost::unit_test::log::end();
boost::unit_test::framework::assertion_result(
result.passed() ? boost::unit_test::AR_PASSED : boost::unit_test::AR_FAILED);
}
};
struct Fixture
{
Fixture()
{
auto& suite{ boost::unit_test::framework::master_test_suite() };
::testing::InitGoogleMock(&suite.argc, suite.argv);
// hook up the gmock and boost test
auto& listeners{ ::testing::UnitTest::GetInstance()->listeners() };
delete listeners.Release(listeners.default_result_printer());
listeners.Append(new HookupListner);
}
~Fixture()
{
}
};
BOOST_GLOBAL_FIXTURE(Fixture);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment