Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mock method with 11 parameters with gmock

I'm using gmock to mock my dependencies in legacy code. One of the class have a method with 11 parameters. When I tried to use MOCK_METHOD11_WITH_CALLTYPE to mock it, I found this macro doesn't exist. gmock only supoort up to 10 parameters. What do you suggest for this? Do I implement this method with dummy body? Or copy & extend the macro? Thanks!

PS, I don't need to mock this method in my tests right now, but probably need to do so in the future.

Best regards,

like image 913
Archer Avatar asked Mar 21 '13 03:03

Archer


1 Answers

Methods with more than 10 parameters may be a sign of trouble. I can suggest a workaround which will help your specific case but which may also be a good idea apart from mocking. Take several of the parameters that make sense as a group, and aggregate them in a struct. Then pass an instance of that struct as an argument to the method. So instead of 11 arguments you might then have 3 or 4. Not only does this help with the mock library problem you're having, it may improve the usability of your class, since methods with so many arguments are usually difficult to read at the call site.

like image 56
John Zwinck Avatar answered Oct 24 '22 17:10

John Zwinck