Skip to content

gomons/comock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

comock - C++ Object MOCK library

Header only library for mocking C++ classes and interfaces. It is designed to be simple and easy to use, while providing powerful features for mocking and testing.

Branch Status
Main comock

Thread Safety

This library is not thread-safe.

  • Repo and created mocks are intended to be used from a single thread.
  • Concurrent calls to mocks from multiple threads may cause race conditions or unexpected behavior.

Requirements

Test requirements

Simple example

#include <comock/comock.h>
#include <iostream>

class Interface {
 public:
  virtual ~Interface() = default;

  virtual int foo(int a, std::string b) = 0;
};

COMOCK_DEFINE_BEGIN(Mock, Interface)
// COMOCK_METHOD(method-name, return type, argument types, specifiers)
   COMOCK_METHOD(foo, int, (int)(std::string), (override))
COMOCK_DEFINE_END

int main() {
  auto repo = comock::Repo{};
  auto const mock = repo.create<Mock>();

  repo.expectCall("foo", *mock, &Interface::foo, [](int a, std::string b) {
    std::cout << "foo called with " << a << " and " << b << "\n";
    return 0;
  });

  return mock->foo(42, "test");
}

About

C++ Object MOCK library

Topics

Resources

License

Stars

Watchers

Forks

Languages