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

Mocking Nested Functions #631

Closed
rushmakes opened this issue Sep 27, 2021 · 2 comments
Closed

Mocking Nested Functions #631

rushmakes opened this issue Sep 27, 2021 · 2 comments

Comments

@rushmakes
Copy link

Sorry I couldn't find the solution to this problem.
So I am writing a unit test for a sensor API. The API has a sensor.c, sensor.h and sensor_types.h file.
sensor.c has various functions needed to access the sensor, these functions are declared in the sensor.h and sensor_types.h has some constants. Also, there are HAL files for i2c communication.
Now, the real problem here is, consider the function given below, sensor_init, funcA and funcB all are in same file sensor.c.
eg: int8_t sensor_init(some struct){
funcA{}
i2c_read()
funcb{}
i2c_write()
}

I was able to write unit tests and test the funcA and funcB as they don't depend on anything else. Also, for the i2c_read and write I was able to write unit tests.
My problem is writing unit test for sensor_init, I cannot directly mock funcA and funcB as they belong to the same file.
I tried creating a dummy header file containing the declaration of dummy_funcA and dummy_funcB, and mocking this header into the test file. I changed the name to avoid conflict. Is this a right approach.?
Also I don't understand how to handle this nested function situation? Any clue would be very helpful

@JuPrgn
Copy link
Contributor

JuPrgn commented Sep 27, 2021

This can be usefull #604
ThrowTheSwitch/CMock#365

@mkarlesky
Copy link
Member

Closing this issue to cull open issues. Issue #936 collects issues related to this one.

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

3 participants