# cppunit in VC++2008 Express (SOLVED)

This topic is 3559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. Just downloaded cppunit to try out in my projects, but I can't compile it in VC++ 2008 Express. I looked on google and the cppunit website but I could not find any info on this. Has anyone here compiled it on this? if so, could you give instructions or a link to the precompiled libs? thanks. [Edited by - dean nolan on April 23, 2008 8:34:06 AM]

##### Share on other sites
So what errors do you get, is it related to MFC as the building docs mentions about 2005 express?

##### Share on other sites
What errors do you get while compiling?

##### Share on other sites
I can't remember off hand as I was at work. :(
I will try again when I get home and will look into the 2005 MFC building in the docs and see if that helps.

I will let you know later how it goes, if well I will upload the compiled headers if anyone wants to use them, unless that's against the licence of using cppunit? I will have to check.

Thanks.

##### Share on other sites
So I managed to compile the lib in VS2005 at work, the website says that express editions can't build it.

I then try a sample project using VSC++ 2008 Express (my compiler as it's free)

I get the following errors:
[Source]
cppunitd.lib(TestFactoryRegistry.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::~_Container_base(void)" (__imp_??1_Container_base@std@@QAE@XZ) referenced in function "public: __thiscall std::_Tset_traits<class CppUnit::TestFactory *,struct std::less<class CppUnit::TestFactory *>,class std::allocator<class CppUnit::TestFactory *>,0>::~_Tset_traits<class CppUnit::TestFactory *,struct std::less<class CppUnit::TestFactory *>,class std::allocator<class CppUnit::TestFactory *>,0>(void)" (??1?$_Tset_traits@PAVTestFactory@CppUnit@@U?$less@PAVTestFactory@CppUnit@@@std@@V?$allocator@PAVTestFactory@CppUnit@@@4@$0A@@std@@QAE@XZ)
cppunitd.lib(TestSuite.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::~_Container_base(void)" (__imp_??1_Container_base@std@@QAE@XZ)
cppunitd.lib(TestPath.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::~_Container_base(void)" (__imp_??1_Container_base@std@@QAE@XZ)
cppunitd.lib(TestFactoryRegistry.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::_Container_base(void)" (__imp_??0_Container_base@std@@QAE@XZ) referenced in function "public: __thiscall std::_Tset_traits<class CppUnit::TestFactory *,struct std::less<class CppUnit::TestFactory *>,class std::allocator<class CppUnit::TestFactory *>,0>::_Tset_traits<class CppUnit::TestFactory *,struct std::less<class CppUnit::TestFactory *>,class std::allocator<class CppUnit::TestFactory *>,0>(struct std::less<class CppUnit::TestFactory *>)" (??0?$_Tset_traits@PAVTestFactory@CppUnit@@U?$less@PAVTestFactory@CppUnit@@@std@@V?$allocator@PAVTestFactory@CppUnit@@@4@$0A@@std@@QAE@U?$less@PAVTestFactory@CppUnit@@@1@@Z) cppunitd.lib(TestSuite.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::_Container_base(void)" (__imp_??0_Container_base@std@@QAE@XZ) cppunitd.lib(TestPath.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Container_base::_Container_base(void)" (__imp_??0_Container_base@std@@QAE@XZ) cppunitd.lib(TestSuite.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::_Container_base::_Orphan_all(void)const " (__imp_?_Orphan_all@_Container_base@std@@QBEXXZ) referenced in function "protected: void __thiscall std::vector<class CppUnit::Test *,class std::allocator<class CppUnit::Test *> >::_Tidy(void)" (?_Tidy@?$vector@PAVTest@CppUnit@@V?\$allocator@PAVTest@CppUnit@@@std@@@std@@IAEXXZ)
cppunitd.lib(TestPath.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::_Container_base::_Orphan_all(void)const " (__imp_?_Orphan_all@_Container_base@std@@QBEXXZ)
C:\Documents and Settings\deann\My Documents\Visual Studio 2008\Projects\core\Debug\core.exe : fatal error LNK1120: 3 unresolved externals
Build log was saved at "file://c:\Documents and Settings\deann\My Documents\Visual Studio 2008\Projects\core\core\Debug\BuildLog.htm"
core - 9 error(s), 0 warning(s)
[/Source]

my source code is;
[Source]

#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>

#pragma comment(lib,"cppunitd.lib")

int main(int argc, char* argv[])
{
// Get the top level suite from the registry
CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();

return 0;
}
[/Source]

the lib is in the correct folder i set up with the VS tools->options and the project settings are setup correctly.

Anyone know what i'm doin wrong?

##### Share on other sites
Well I tried using it in a VS2005 project and it worked. So I played about with compiling for 2008 Express.

The problem is that cppunit uses MFC in its test runner and MFC is not included with express editions :(
So it looks like i'm going to have to use a different unit testing framework.

Oh well.

##### Share on other sites
Quote:
 Original post by dean nolanWell I tried using it in a VS2005 project and it worked. So I played about with compiling for 2008 Express.The problem is that cppunit uses MFC in its test runner and MFC is not included with express editions :( So it looks like i'm going to have to use a different unit testing framework. Oh well.

You might want to try CppUnitLite - it's written by the same guy who wrote CppUnit in the first place, then got cheesed off that it was becoming too heavyweight and bloated.

##### Share on other sites
Another option is UnitTest++. It doesn't have runners or anything fancy, but it's very lightweight and it works perfectly with the express editions of vc++.

##### Share on other sites
I like cxxtest. It does require perl to build the test cases, but this can be trivially added to build process.

It's header only, lightweight, and pretty straight-forward.

##### Share on other sites
I have looked at the other 3 posted. I liked the idea of CppUnitLite but it doesn't support some features I would like, fixtures and the test runner seemed a good idea. Maybe if I was to find a modified version that would be good.

Unit++ seemed like a lot of work to create tests when i looked over it, maybe I'll look again.

And cxxtest seemed like it would be the best one. However, and this was only with a quick glance, getting it integrated with Visual Studio I have to have 3 extra projects in my solution?

Maybe I am missing something though ;)

Thanks for the suggestions.

##### Share on other sites
Quote:
 Original post by dean nolanI have looked at the other 3 posted. I liked the idea of CppUnitLite but it doesn't support some features I would like, fixtures and the test runner seemed a good idea. Maybe if I was to find a modified version that would be good.

The idea behind CppUnitLite is that you use it as a starting point and modify it to suit your needs. I found it fairly trivial to add fixture support (just add a base class with setup() and teardown() calls via the TEST macro). If you want something that works "out of the box" with no modifications then CppUnitLite might not be your best choice.

Not sure what you mean by "the test runner" though?

##### Share on other sites
Quote:
 Original post by dean nolanUnit++ seemed like a lot of work to create tests when i looked over it, maybe I'll look again.

1) you need to build the library.
2) you need to call RunAllTests from within your application.
3) to add a test simply add TEST(NameOfThisTest){/*testcode here*/}

When I want to test code from a static lib, I always create a console test project that links the library:

StaticLib.vcproj
+--MyClass.h
+--MyClass.cpp
StaticLibTest.vcproj //this project runs itself in a post-build event
+--main.cpp //only does "return RunAllTests();" in its main function
+--MyClassTest.cpp //contains all tests for MyClass

This way the tests get run automatically when building. I like this system because you don't need any extra stuff but your compiler/build system.

[Edited by - Koen on April 24, 2008 7:44:42 AM]