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

  • SEARCH
  • Home
  • 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 7600835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:00:43+00:00 2026-05-30T23:00:43+00:00

I have a set of generic unit tests in a .hpp file that more

  • 0

I have a set of generic unit tests in a .hpp file that more than one test file must include.

But it gets multiple copies of the same file and the generic .hpp file complaints about multiple definition of the Test fixtures.

Need help on how to approach this.

  • 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-30T23:00:44+00:00Added an answer on May 30, 2026 at 11:00 pm

    You should be able to separate the gtest class declarations from the definitions in the usual way using .hpp and .cpp files.

    So rather than defining the test functions and fixtures in the header, move these to a source file which #includes the header. So if e.g. you have test.hpp as:

    #include "gtest/gtest.h"
    
    class MyTest : public ::testing::Test {
     protected:
      void TestFunction(int i) {
        ASSERT_GT(10, i);
      }
    };
    
    TEST_F(MyTest, first_test) {
      ASSERT_NE(1, 2);
      TestFunction(9);
    }
    

    change test.hpp to:

    #include "gtest/gtest.h"
    
    class MyTest : public ::testing::Test {
     protected:
      void TestFunction(int i);
    };
    

    and add test.cpp:

    #include "test.hpp"
    
    void MyTest::TestFunction(int i) {
      ASSERT_GT(10, i);
    }
    
    TEST_F(MyTest, first_test) {
      ASSERT_NE(1, 2);
      TestFunction(9);
    }
    

    If you’re including the same test header in multiple places are you really looking for typed tests or type-parameterised tests? See http://code.google.com/p/googletest/wiki/V1_6_AdvancedGuide#Typed_Tests for further details.

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

Sidebar

Related Questions

We have a decent set of unit tests on our code and those unit
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set of flat files (114 files) each file is named with database
I have set up an app that is registered for remote notifications. - (void)application:(UIApplication*)application
I have set onItemClicklistener on my custom list view but onItemClicklistener not working I
I have a simple unit test where I execute the same NHibernate named query
I have set up this programming exercise. using System; using System.Collections.Generic; using System.Linq; using
I have a generic repository that is using Entity Framework 4 with the DbContext
I have a swf one one server that is pulling content from an Amazon
I have an interface, IFindable that is implemented by a few classes. One other

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.