Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3498982
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:33:21+00:00 2026-05-18T12:33:21+00:00

I like the things that templates methods can do for me, since they can

  • 0

I like the things that templates methods can do for me, since they can be used to dramatically simplify some code I’d otherwise have to write over and over.

However, I have a very hard time testing any classes that depend on collaborators that have public template methods. The real problem is they can’t be virtual, so my usual method of subclassing dependencies and stubbing doesn’t work.

Presently, my solution is to create a non-templated interface that includes every type that’s supported, then use the templates as an implementation detail. This is testable, but is tedious to update for large numbers of types passing through many classes. I suppose I could also redesign to use inheritance-based polymorphism instead, but if my problems with testing could be solved without a system redesign I’d prefer that.

I thought there might be something I could do with using template specialization to change the behaviour in my test library vs. my production library, but I’m not sure if that’s effective… or even possible.

So, what’s the best way of testing classes that use templated methods in their dependencies?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:33:22+00:00Added an answer on May 18, 2026 at 12:33 pm

    Google mock framework provides a way to create a mock with template parameters. Then you have to add a templated base class and pass a mock object to the constructor of the class under test.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have lots of unrelated named things that I'd like to do quick searches
We already have things like static analysis that tells us what's wrong with our
I am looking for things like reordering of code that could even break the
I've come across a few examples recently that do things like: <dl> <dt>Full Name:</dt>
So right now my project has a few custom dialogs that do things like
I like .NET webcontrols and you manipulate things, that's common consensus, but XML and
Here's a coding problem for those that like this kind of thing. Let's see
Things like $log$ and $version$ which add data upon check-in to the file. I'm
I've seen people doing things like this in their HTML: <!--[if IE]> <link rel=stylesheet
I'm aware of things like onchange , onmousedown and onmouseup but is there a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.