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
I am testing C-Mock extension. Everything seems good. I can mock C type functions.
But, one of this mocked functions is called from a class's constructor. When I define a global instance, I get error from cmock-function-mockers.h, line=100. (error msg= Neither mock nor real function is present)
I made a change as below. It fixed my problem. Is there any better solution that you recommend?
The text was updated successfully, but these errors were encountered:
the exception is thrown because the constructor of a global class is called before the internal state of C-Mock is initialized. C-Mock was designed with the assumption a mocked function is called from the test code only. In your case, the code in question is called before a test suit even runs.
Your proposition allows a mocked function to be called outside a test. Since I don't know your case well enough I can only offer only general alternative suggestions.
A client might not expect side effects during an object instantiation hence it's reasonable to avoid them in constructors.
A global object having a state might lead to dependency between tests. You're better off having dedicated object instances per test.
Hello,
I am testing C-Mock extension. Everything seems good. I can mock C type functions.
But, one of this mocked functions is called from a class's constructor. When I define a global instance, I get error from cmock-function-mockers.h, line=100. (error msg= Neither mock nor real function is present)
I made a change as below. It fixed my problem. Is there any better solution that you recommend?
The text was updated successfully, but these errors were encountered: