{"id":19440956,"url":"https://github.com/cpp-testing/mocks_injector","last_synced_at":"2025-04-24T23:32:20.656Z","repository":{"id":18594127,"uuid":"21798761","full_name":"cpp-testing/mocks_injector","owner":"cpp-testing","description":"C++ Automatic Mocks Injector","archived":false,"fork":false,"pushed_at":"2015-02-09T11:09:22.000Z","size":640,"stargazers_count":34,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"cpp14","last_synced_at":"2025-04-03T13:03:10.063Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cpp-testing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-13T19:57:47.000Z","updated_at":"2025-04-02T13:17:08.000Z","dependencies_parsed_at":"2022-09-12T08:51:15.020Z","dependency_job_id":null,"html_url":"https://github.com/cpp-testing/mocks_injector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpp-testing%2Fmocks_injector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpp-testing%2Fmocks_injector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpp-testing%2Fmocks_injector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpp-testing%2Fmocks_injector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cpp-testing","download_url":"https://codeload.github.com/cpp-testing/mocks_injector/tar.gz/refs/heads/cpp14","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250727803,"owners_count":21477373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T15:33:24.264Z","updated_at":"2025-04-24T23:32:20.379Z","avatar_url":"https://github.com/cpp-testing.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"**C++ Automatic Mocks Injector**\n\n## Introduction\nC++ Automatic Mocks Injector is C++14 header only library providing following functionality:\n* Automatically create required mocks\n* Automatically inject mocks to tested classes via constructor\n* Automatically register for required destructor's in case of smart pointers (supports testing of unique\\_ptr)\n* Uses [HippoMocks](https://github.com/dascandy/hippomocks) as Mocking library\n* Uses [DI](https://github.com/krzysztof-jusiak/di) as Dependency Injection library\n\n### Unit Tests\n```cpp\n#include \u003cstring\u003e\n#include \u003cmemory\u003e\n#include \u003cutility\u003e\n\nstruct ilogger { virtual ~ilogger() { }; virtual void log(const std::string\u0026) = 0; };\nstruct ilogic { virtual ~ilogic() { }; virtual void do_it() = 0; };\n\nclass example {\npublic:\n    example(const std::shared_ptr\u003cilogger\u003e\u0026 logger\n          , std::unique_ptr\u003cilogic\u003e logic\n          , const std::string\u0026 text)\n        : logger_(logger)\n        , logic_(std::move(logic))\n        , text_(text)\n    { }\n\n    int run() {\n        logic_-\u003edo_it();\n        logger_-\u003elog(text_);\n        return 0;\n    }\n\nprivate:\n    std::shared_ptr\u003cilogger\u003e logger_;\n    std::unique_ptr\u003cilogic\u003e logic_;\n    std::string text_;\n};\n\n#include \u003cmocks_injector.hpp\u003e\n\nint main() {\n    namespace di = boost::di;\n\n    //1. create mocks injector and example class\n    auto _ = di::make_injector\u003cdi::mocks_provider\u003e();\n\n    //2. set up expectations\n    EXPECT_CALL(_, ilogic::do_it);\n    EXPECT_CALL(_, ilogger::log).With(\"hello world\");\n\n    //3. run tests\n    example sut{_, _, \"hello world\"};\n    assert(0 == sut.run());\n}\n```\n\n### Integration Tests\n```cpp\nstruct logic : ilogic { void do_it() override { } };\n\nclass app {\npublic:\n    app(std::shared_ptr\u003cexample\u003e e)\n        : example_(e)\n    { }\n\n    int run() {\n        return example_-\u003erun();\n    }\n\nprivate:\n    std::shared_ptr\u003cexample\u003e example_;\n};\n\n#include \u003cmocks_injector.hpp\u003e\n\nint main() {\n    namespace di = boost::di;\n\n    //1. create mocks injector with dependencies\n    auto mi = di::make_injector\u003cdi::mocks_provider\u003e(\n        di::bind\u003cstd::string\u003e.to(\"hello world\")\n      , di::bind\u003cilogic, logic\u003e // inject real logic\n    );\n\n    //2. set up expectations\n    EXPECT_CALL(mi, ilogger::log).With(\"hello world\");\n\n    //3. create example class and run it\n    assert(!mi.create\u003capp\u003e().run());\n}\n```\n\n## License\nDistributed under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpp-testing%2Fmocks_injector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcpp-testing%2Fmocks_injector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpp-testing%2Fmocks_injector/lists"}