Giter Site home page Giter Site logo

cpputest_mockify's Introduction

CppUTest mockify

license: ISC build status

Easily generate mocks to be used with the CppUTest mocking framework. lowering the barrier to writing C unit tests. Interested in how this can help you? Check out this great post from the guys at Memfault.

Usage

To generate a .cpp mock file, run:

cpputest_mockify.py <input_file.h> <output directory>

Afterward, scan the output file for instances of FIXME, CHECKME, or WRITEME, indicating areas where manual intervention is required.

Benefits

  • Stupid simple to use
  • No external dependencies
  • No need to configure include paths or otherwise tell it anything about your build
  • Compatible with Python 2 and 3

Drawbacks

In the end, the script boils down to a surprisingly-effective but very hacky regex 🤷

To keep usage (and the implementation) simple, it doesn't use a real C language parser (e.g. pycparser) so it's not to going to work reliably 100% of the time. For example, array parameters aren't really handled well. In practice, on real code™, it will get you ~80-90% of the way there and let you know when it needs further help.

The script doesn't currently do incremental mock generation. If you add a new function to your header file, you're best off overwriting your old mock and relying on version control to manage the changes.

Other contributors

Thanks to Noah Pendleton and Alan Rosenthal for cleaning up my hacks and adding functionality. Also to https://github.com/marco-m/mockify, the original inspiration for the script.

Alternatives

cpputest_mockify's People

Contributors

kesyog avatar noahp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

noahp

cpputest_mockify's Issues

Run clang-format on the output

I had to remove a change from @noahp to run clang-format on the output. For some reason, the subprocess call was hanging. Need to dig into it more.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.