You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
The text was updated successfully, but these errors were encountered: