Open git45016683 opened 1 year ago
You need to make the A member accessible in the test so that you can place an expectation on it. One traditional technique for this is dependency injection, i.e. you create your B with the mocked A for the test.
Yeah, I know what you mean, but that's a real huge workload, because there's a lot of historical code (T_T). And they are running at product.... So, i want to found some solution that can integrated unit testing without requiring too many source code changes。 There are many codes like demo in historical code。Although not the best, but it work。 So i can not change every class to dependency injection。 Thanks。
Well, the library can only work within the rules of the language. For this to work you need:
With those you can place expectations on the mock and test your code. If those are not acceptable, then I'm afraid I cannot help.
This is a common scenario: class B has an A object, so class B member function can call class A member function with A object. so how can i mock class A member function when i perform unit testing on class B member function? example code like below:
the unit test code like below:
I expect iTest_OutputValueByPointer call vOutputValueByPointer mock function and l_acStr equal “HELLOWORLD”, but iTest_OutputValueByPointer actually call class memberFuncHeader function then output 'origin' to l_acStr.
can do this with trompeloeil? and i push the demo code at demo