All Projects → cpp-testing → Gmock.py

cpp-testing / Gmock.py

'Google Mock' mocks generator based on libclang

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Gmock.py

Ohhttpstubs
Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
Stars: ✭ 4,831 (+13702.86%)
Mutual labels:  mocking
Cmake Ide
Use Emacs as a C/C++ IDE
Stars: ✭ 661 (+1788.57%)
Mutual labels:  libclang
Irony Mode
A C/C++ minor mode for Emacs powered by libclang
Stars: ✭ 851 (+2331.43%)
Mutual labels:  libclang
Easyclangcomplete
💥 Robust C/C++ code completion for Sublime Text 3
Stars: ✭ 537 (+1434.29%)
Mutual labels:  libclang
Mongomock
Small library for mocking pymongo collection objects for testing purposes
Stars: ✭ 615 (+1657.14%)
Mutual labels:  mocking
Jucipp
A lightweight & cross-platform IDE supporting the most recent C++ standards. This project has moved to https://gitlab.com/cppit/jucipp.
Stars: ✭ 887 (+2434.29%)
Mutual labels:  libclang
Studio
The modern editor for API Design and Technical Writing.
Stars: ✭ 459 (+1211.43%)
Mutual labels:  mocking
Moq
Interface mocking tool for go generate
Stars: ✭ 941 (+2588.57%)
Mutual labels:  mocking
Mockhttp
Testing layer for Microsoft's HttpClient library. Create canned responses using a fluent API.
Stars: ✭ 623 (+1680%)
Mutual labels:  mocking
Color coded
A vim plugin for libclang-based highlighting of C, C++, ObjC
Stars: ✭ 841 (+2302.86%)
Mutual labels:  libclang
Mock Socket
Javascript mocking library for WebSockets and Socket.IO
Stars: ✭ 598 (+1608.57%)
Mutual labels:  mocking
Msw
Seamless REST/GraphQL API mocking library for browser and Node.js.
Stars: ✭ 7,830 (+22271.43%)
Mutual labels:  mocking
Pytest Responsemock
Simplified requests calls mocking for pytest
Stars: ✭ 24 (-31.43%)
Mutual labels:  mocking
Kakapo.js
🐦 Next generation mocking framework in Javascript
Stars: ✭ 535 (+1428.57%)
Mutual labels:  mocking
Pose
Replace any .NET method (including static and non-virtual) with a delegate
Stars: ✭ 855 (+2342.86%)
Mutual labels:  mocking
Wiremock
A tool for mocking HTTP services
Stars: ✭ 4,790 (+13585.71%)
Mutual labels:  mocking
Cmockery
A lightweight library to simplify and generalize the process of writing unit tests for C applications.
Stars: ✭ 697 (+1891.43%)
Mutual labels:  mocking
Proxay
Proxay is a record/replay proxy server that helps you write faster and more reliable tests.
Stars: ✭ 32 (-8.57%)
Mutual labels:  mocking
Faker.js
generate massive amounts of realistic fake data in Node.js and the browser
Stars: ✭ 34,329 (+97982.86%)
Mutual labels:  mocking
Clj Fakes
An isolation framework for Clojure/ClojureScript.
Stars: ✭ 26 (-25.71%)
Mutual labels:  mocking

Google Mock mocks generator based on libclang

Code Health

Requirements

Download

git clone --recursive [email protected]:krzysztof-jusiak/gmock.git

Usage

Usage: gmock.py [options] files...

Options:
  -h, --help                show this help message and exit
  -c FILE, --config=FILE    config FILE (default='gmock.conf')
  -d DIR, --dir=DIR         dir for generated mocks (default='.')
  -l LIMIT, --limit=LIMIT   limit to interfaces within declaration (default='')

Example

./gmock.py file.hpp

will create mocks files in current directory for all interfaces

./gmock.py -c "gmock.conf" -d "test/mocks" -l "namespace::class" file1.hpp file2.hpp

will create directory 'test/mocks' and mocks files within this directory for all interfaces (contains at least one pure virtual function) which will be within 'namespace::class' declaration

./gmock.py -d "test/mocks" file1.hpp file2.hpp -- -D PROJECT -Iproject/include

'--' separates arguments between script and compiler

Integration with the build system

find project -iname "*.h" -or -iname "*.hpp" | xargs "project/externals/gmock.py"   \
    -c "project/conf/gmock.conf"                                                    \
    -d "project/test/mocks"                                                         \
    -l "Project"                                                                    \
    --                                                                              \
    -D PROJECT                                                                      \
    -Iproject/include                                                               \

Features

  • it's reliable (based on clang compiler)
  • it's fast (tested on project ~200 kloc -> generation of mocs takes 3-5s on common laptop)
  • output file might be easily adopted to the project via configuration file
  • easy integration with the project build system -> generate mocks files for each interface from given files limited to the project (for example via project namespace)
  • able to generate cpp files with default constructors (to speed up compilation times)
  • generate pretty output (one mock per file)
  • mocking class templates
  • easy to extend (~300 lines of code)
  • handle c++ operators
    virtual int operator()(int, double) = 0;
    virtual int operator()(int arg0, double arg1) { return call_operator(arg0, arg1); }
    MOCK_METHOD2(call_operator, int(int, double));

Configuration file

#possible variables:
# file: interface file name
# dir: interface directory
# guard: header guard
# template: template parameters
# template_interface: template interface class
# interface: interface class
# mock_methods: generated gmock methods
# generated_dir: generated directory
# mock_file_hpp: mock header file
# mock_file_cpp: mock source file

mock_file_hpp = "%(interface)sMock.hpp"

file_template_hpp = """\
/*
 * file generated by gmock: %(mock_file_hpp)s
 */
#ifndef %(guard)s
#define %(guard)s

#include <gmock/gmock.h>
#include "%(dir)s/%(file)s"

%(namespaces_begin)s

%(template)sclass %(interface)sMock : public %(template_interface)s
{
public:
%(mock_methods)s
};

%(namespaces_end)s

#endif // %(guard)s

"""

mock_file_cpp = ""
file_template_cpp = ""

Example of generated output

/*
 * file generated by gmock: I2Mock.hpp
 */
#ifndef I2MOCK_HPP
#define I2MOCK_HPP

#include <gmock/gmock.h>
#include "I2.hpp"

namespace n {

class I2Mock : public I2
{
public:
    MOCK_CONST_METHOD0(f0, void());
    MOCK_METHOD1(f1, void(int));
    MOCK_METHOD1(f2, void(double));
    MOCK_METHOD2(f3, void(int, double));
    MOCK_METHOD3(f4, void(int, double, const std::string &));
    MOCK_METHOD1(f5, int(const std::string &));
    MOCK_CONST_METHOD1(f6, boost::shared_ptr<int>(const boost::shared_ptr<int> &));
    MOCK_CONST_METHOD0(f7, const int&());
    MOCK_METHOD0(f8, boost::function<void(int)>());
    MOCK_CONST_METHOD1(f9, boost::non_type<int,0>(const boost::non_type<int, 1> &));
    MOCK_METHOD0(f10, const int*const ());
    MOCK_METHOD0(f11, const void());
    virtual int operator()() { return function_call_or_cast_operator(); }
    MOCK_METHOD0(function_call_or_cast_operator, int());
};

} // namespace n

#endif // I2MOCK_HPP

/*
 * file generated by gmock: TMock.hpp
 */
#ifndef TMOCK_HPP
#define TMOCK_HPP

#include <gmock/gmock.h>
#include "T.hpp"

namespace n {

template<typename Elem>
class TMock : public T<Elem>
{
public:
    MOCK_CONST_METHOD0_T(GetSize, int());
    MOCK_METHOD1_T(Push, void(const Elem &));
};

} // namespace n

#endif // TMOCK_HPP

License

Distributed under the Boost Software License, Version 1.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].