Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to mock functions that are inside a tested file ? #482

Open
lesnake opened this issue Sep 16, 2024 · 0 comments
Open

How to mock functions that are inside a tested file ? #482

lesnake opened this issue Sep 16, 2024 · 0 comments

Comments

@lesnake
Copy link

lesnake commented Sep 16, 2024

Hello,
In a source file, I have function that only call functions declared and defined outside this source file. Mocking these functions is easy and straight forward (thanks for the job, btw).
In this source file, some functions are calling functions also defined inside the same file.
How can I mock these ?

Here is a foobar example :
inside foo.c

#include "bar.h"
#include "foo.h"

foo_init
{
  bar_init()
}

foo_sub1
{
  bar_sub1
}

foo_sub2
{
  bar_sub2
}

foo_main
{
  foo_init

  foo_sub1

  foo_sub2
}

inside test_foo.c

#include "mockbar.h"
#include "mockfoo.h"

test_foo_init()
{
  mockbar_init()
  foo_init()
}

test_foo_sub1
{
  mockbar_sub1()
  foo_sub1()
}

test_foo_sub2
{
  mockbar_sub2()
  foo_sub2()
}

//This function need to access to mocked versions of foo_init, foo_sub1, foo_sub2 
// But also to unmocked version of foo_main
// This is where I am stuck
test_foo_main
{
  mockfoo_init()

  mockfoo_sub1()

  mockfoo_sub2()

  // unmocked
  foo_main()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant