Last active
September 4, 2016 22:57
-
-
Save alanduan/6ab560575e3fb1cfd7ec8392e123cb68 to your computer and use it in GitHub Desktop.
Google Mock & Boost Test, support static lib and dynamic lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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