# Unit Testing

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

## Recommended Posts

Greetings! I was wondering if anyone is using anything simplier than CPPUNIT (sourceforge). I need a unit testing application that I could easily integrate with my small proggy. I am ussing C++ and would like to have something smaller than CPPUNIT because it is way too much for my small 8 files max loading library. But anyway, I would like that may progys are future proof and that some tests with results generation can be generated. I do not want some unix stuff (.gz) i would just like it simple. Any suggestions? The code is 4k of lines max. I do not want that the unit testing module takes more than a few kilos! Thank you in advance!

##### Share on other sites

I do this:

// file.cppcode stuff goes here#if !defined( NDEBUG )namespace {  class UnitTest {  public:    UnitTest() {      test goes here; tests with assert()    }  };  static UnitTest test;};#endif

So, each time I start the program in debug mode, the unit tests run and ensure that the program is wholesome. Can't get easier than that.

Because the unit tests live inside the .cpp file that implements the classes, I can also poke at otherwise not-visible members (because I use abstract interfaces in header files, and concrete implementation classes declared and defined in .cpp files, so I don't need ot make members private).

##### Share on other sites
ah, darn! If I had it packed up proberly I would have pimped my own testing framework "bUn" since it's aimed just for things like that.

for those intrested bUn looks like this:
BUN_AUTO_TEST(SimpleTest){  BUN_ASSERT( something());  BUN_ASSERT_EQUAL( answer(), 42);}

using fixtures looks like:
BUN_FIXTURE(MyFixture){  MyFixture()//setup  {}  ~MyFixture()//teardown  {}  MyClass ThingInFixture;};BUN_AUTO_TEST_F(MyFixture, TestWithFixture){  BUN_ASSERT/*etc*/(ThingInFixture.baz());}

auto tests are automaticly added to the global registry and stuffage so it's impossible to forget registration and silly things like that.

oh, and basic functionality only requires the inclusion of a header.

I really ought to make it publicly available soon.
Thanks for reminding me.

##### Share on other sites
Quote:
 Original post by Samurai JackThe code is 4k of lines max. I do not want that the unit testing module takes more than a few kilos!

Why does it matter? You don't have to deploy the unit testing code or its dependencies.

##### Share on other sites
Quote:
 Original post by Arild FinesWhy does it matter? You don't have to deploy the unit testing code or its dependencies.

True, but CppUnit is bulky in my oppinion quite error prone and mostly ill suited for small projects I guess using it makes sense on larger projects that need the advanced features I guess it must have somewhere.

But in a sense small really is beatiful for a testing framework, realyl making tests should be easy that's the whole point of TDD and that's the aspect I think CppUnit fails quite miserably in.

##### Share on other sites
Exploring the C++ Unit Testing Framework Jungle

##### Share on other sites
I've been using CxxTest and it's easy to use and fairly lightweight. I have it integrated into my VS build process so I can run my tests at any time by just running my unit test config.

As for the size of your unit testing module staying small I think that's more dependant on the number of tests you want to create than anything else. CxxTest creates one core cpp file to run the tests you create in one or more header files. The cpp file is tiny since it just references your test classes.

##### Share on other sites
well, as my earlier threads this week indicate, I have got up and running with CppUnit, and I like it a lot. Already improved a bunch of code far more than I expected.

CppUnit isn't that hard to get working, once you know what is necessary, which is nicely explained in one of it's example pages. I highly recommend taking the time to get it working.

I also considered putting the tests into my source files, but I decided I didn't want the extra complexity, so separate unit test projects are the way for me for each library.

If you have any problems getting CppUnit working, just post here, and I'll help as much as I can. It is worth it.

*edit* and oh yeah, while you may correctly say it is maybe a little strict for a small project, when you build something larger, you will be pleased you already know how to use it.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015433
×