I found this code:
#define mockable virtual
Do you have any idea why 开发者_高级运维somebody will define virtual like this? I'm just curios what's the point of doing this
So that you could do:
class ClassIdLikeToTest{
mockable void mymethod(){
//Behavior I would like to be different in my tests
}
}
And then define mockable as virtual for the test build so that you can override that method inheriting from the class.
You write your test and use a class that inherits from ClassIdLikeToTest and overrides mymethod, and it will work as long as mockable is virtual, but then you can remove it for production builds and those functions will not be virtual, and you don't pay for the virtual call.
精彩评论