Is Google Test OK for testing C code?

前端 未结 5 1029
死守一世寂寞
死守一世寂寞 2020-12-25 10:31

So I\'ve come to like and enjoy using Google Test for a C++ project I\'m involved in. I\'m just bringing up a new project that will be straight C (a library) and so far can

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-25 11:11

    Jason, be aware of that!!! :D

    As Meekrosoft said, yes, it is possible. I also used his website when I tried to do that. It works, but there is one big problem:

    GTest is objected oriented tool and C language isn't!

    In example, in GTest you have a lot of functions (80% of whole API) that request object as parameter, for example:

    EXPECT_CALL(turtle, PenDown())              // turtle is object(class) and PenDown() is method of that object
          .Times(AtLeast(1));
    

    from GTest website https://code.google.com/p/googlemock/wiki/ForDummies so you will use only macros like expect_equal, expect_bigger_than and so on...

    I would like to suggest you tool CMocka (or some other C unit testing tools). It is also from google (modified by group of non-google developers) and it is created directly for C language. I use this one when I want to test C-type source code.

    I hope this helps.. :-) Have a nice day.. :-)

提交回复
热议问题