suggestion library for mocking C functions
Shivansh Rai
shivansh at freebsd.org
Thu Sep 28 06:42:52 UTC 2017
To add to the information by asomers@, this comment [1] might also be
relevant.
[1]: https://github.com/google/cmockery/pull/30#issuecomment-251064107
Regards,
-- Shivansh
On Sun, Sep 24, 2017 at 9:52 PM Alan Somers <asomers at freebsd.org> wrote:
> On Sun, Sep 24, 2017 at 1:05 AM, John-Mark Gurney <jmg at funkthat.com>
> wrote:
> > Is there a recommended/supported library for mocking C functions?
> >
> > I want to write some test cases for functions that call other code
> > in the same compilation unit that I want to be able to mock.
> >
> > There are a few out there, but was wondering if anyone has suggestions?
> >
> > Thanks.
> >
> > --
> > John-Mark Gurney Voice: +1 415 225 5579
> <(415)%20225-5579>
>
> There is no good C mocking library. The language simply doesn't
> provide a good way to do it. CMockery is the best I've seen.
> However, it's got some big limitations because it relies on the linker
> to swap out function implementations. Your other option is to use a
> C++ mocking library. It's usually possible to build your application
> as C, but build the tests as C++. However, you'll still need to make
> a few modifications to the application source to be able to mock
> functions. You can probably hide it all in the preprocessor. If you
> go this route, I recommend googletest, which nowadays includes mocking
> functionality too.
>
> https://github.com/google/cmockery
> https://github.com/google/googletest
>
> -Alan
> _______________________________________________
> freebsd-testing at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-testing
> To unsubscribe, send any mail to "freebsd-testing-unsubscribe at freebsd.org"
>
More information about the freebsd-testing
mailing list