0

How a unit test can be made for this kind of structure?
How to change the call so function a() will call function mock_b() instead of function b().

// source.h
int b(int x);
bool a();


// source.cpp
int b(int x){return x;}
bool a(){return (b(5) > 0);}


// tester.cpp
#include "source.h"
int mock_b(int x){return -8;}

unit_test(){
    assert(true == a());
    b = mock_b;                 //How this replacement can be done?
    assert(false == a());
}
Ronen333
  • 69
  • 1
  • 8
  • It is complicated, as your design is not good for separate tests. -- Don't test functions or methods separately, test features. -- You might want to search this site for duplicates of your question, unfortunately I don't have the time right now. – the busybee Jun 15 '22 at 20:27
  • Generally you can do `#define b mock_b`. – Lundin Jun 17 '22 at 06:57

0 Answers0