fake/mock nonvirtual C++ methods

后端 未结 8 1681
谎友^
谎友^ 2020-12-13 19:32

It known that in C++ mocking/faking nonvirtual methods for testing is hard. For example, cookbook of googlemock has two suggestion - both mean to modify original source code

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 20:14

    One way that we sometimes use is to split the original .cpp file into at least two parts.

    Then the test apparatus can supply its own implementations; effectively using the linker to do the dirty work for us.

    This is called the "Link Seam" in some circles.

提交回复
热议问题