0

I have a C project with 2 modules - A and B. B has a function that calls a function from A.

int B_func() {
  if (1 == A_func()) {return 1;}
  return 2;
 }

I use unity to test these modules.

TEST(B, test_b) {
  TEST_ASSERT_EQUAL(1, B_func())
}

When I test module B, I want to mock A_func so it will use my implementation and change the return value. Is there a way to do this without changing the source code of module B?

2
  • I don't see your problem. The function is not implemented in B. So why not? (and why mock, just change A_func.) Commented Sep 24, 2017 at 14:36
  • I don't want to change A_func, since it is already part of the project and is linked in. I want to tell B_func to ignore the original implementation of A_func, i.e to mock A_func in B's unit tests... Commented Sep 24, 2017 at 14:43

1 Answer 1

1

I ended up using Mimick. https://github.com/diacritic/Mimick

It's a bit cumbersome. I needed to compile my project as a shared object and link it to my tests so my functions will be in the GOT, so it is not ideal, but successfully solves my problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.