I have two classes A and B. Currently, B is constructed inside of A. Since I want to verify in my unit tests that A calls B's methods correctly, I want to inject B into A instead to enable mocking.
The problem is: Upon construction, B needs one of A's fields as a constructor parameter. Which means that if I inject B and therefore move its construction out of A, I would also have to move that field's construction out of A.
What's the most elegant solution here? I hope I explained the problem properly. If not, please feel free to ask any questions.
// constructor of class A. b_ is being constructed. field_of_a_ is initialized.
A::A() : b_{field_of_a_}, field_of_a_{5} {
}
Aucun commentaire:
Enregistrer un commentaire