代码之家  ›  专栏  ›  技术社区  ›  Alok Save

C++中的模拟对象

  •  4
  • Alok Save  · 技术社区  · 16 年前

    4 回复  |  直到 7 年前
        1
  •  2
  •   Anon    16 年前

    仔细阅读 mockcpp 你会找到问题的答案。mock非常适合用于测试目的,您可以集中精力测试一件事情,并模拟环境中其他部分的行为。

        2
  •  2
  •   Damian Schenkelman    16 年前

    您可以在此处找到更多信息,包括用于测试的各种模拟:

    我希望这有帮助。

    达米安

        3
  •  1
  •   Sandeep    15 年前

    Google Mock 是一个模拟被单元测试类的依赖关系的框架。该网站还包括一个良好的 introduction

        4
  •  1
  •   Eran Pe'er    11 年前

    Fake-It 是一个简单的C++模拟框架。FAKEIT使用最新的C++ 11特性创建一个表达(但非常简单)的API。 下面是你如何伪装的:

    struct SomeInterface {
      virtual int foo(int) = 0;
    };
    
    // That's all you have to do to create a mock.
    Mock<SomeInterface> mock; 
    
    // Stub method mock.foo(any argument) to return 1.
    When(Method(mock,foo)).Return(1);
    
    // Fetch the SomeInterface instance from the mock.
    SomeInterface &i = mock.get();
    
    // Will print "1"
    cout << i.foo(10);
    

    give it a try .