Project

General

Profile

Task #1475

Use google mock tests

Added by Stefan Petscharnig 9 days ago. Updated 4 days ago.

Status:
New
Priority:
Normal
Target version:
-
Start date:
09.08.2018
Due date:
% Done:

0%

Estimated time:

Description

include mock tests

History

#1 Updated by Oliver Maurhart 8 days ago

Sure, ... but could you give an example or some other reasoning? =)

#2 Updated by Stefan Petscharnig 4 days ago

google mock (gmock) allows tests t be decoupled from other class' dependencies.

Therefore, gmock provides measures to provides such mock objects that provide some defined behavior / return values.
Furthermore, we would be able to test more rigorously, as we for example could assert that some functions are called a specified number of times (possibly in a strict order)

some example..


#include "path/to/mock-turtle.h" 
#include "gmock/gmock.h" 
#include "gtest/gtest.h" 
using ::testing::AtLeast;                   

TEST(PainterTest, CanDrawSomething) {
  MockTurtle turtle;                        
  EXPECT_CALL(turtle, PenDown())   // specification of expectation on the mock object         
      .Times(AtLeast(1));

  Painter painter(&turtle);        // some code using the mock object - 

  EXPECT_TRUE(painter.DrawCircle(0, 0, 10));
}            

possible test output:
path/to/my_test.cc:119: Failure
Actual function call count doesn't match this expectation:
Actually: never called;
Expected: called at least once.

Also available in: Atom PDF