Reputation: 3787
I have a C++ (VS 2013) console application and I want to test it (using Google Test).
I created a separate project and added gtest include paths, etc. (for exanple using this tutorial http://www.bogotobogo.com/cplusplus/google_unit_test_gtest.php) and simple tests like this work fine:
TEST(MyTests, myTest1)
{
EXPECT_EQ(2+2, 4);
}
But how to use classes from the main project? If I simply add the project dir to include paths then I can use "header-only" code but for classes with implementation in .cpp
I get unresolved external symbol
error.
Is there any better way than moving all classes to a library just to be able to test it?
Upvotes: 2
Views: 70
Reputation: 8220
Make your project as library. And make little executable for startup. This solves many problems. There are many projects use this strategy. And one of them is Chromium. One another example is Perl language interpreter. Your project-library will be easy to link to tests.
Upvotes: 1