Unit Testing

Started by
6 comments, last by squirrel_of_death 18 years, 8 months ago
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!
Advertisement

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).
enum Bool { True, False, FileNotFound };
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.

but maybe if you google cppunit light that can be helpful?

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.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
Quote:Original post by Samurai Jack
The 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.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Quote:Original post by Arild Fines
Why 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.

HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
Perhaps this article can help you (and anyone looking for a c++ unit testing framework).
Exploring the C++ Unit Testing Framework Jungle
_______________The essence of balance is detachment. To embrace a cause, to grow fond or spiteful, is to lose one''s balance after which, no action can be trusted. Our burden is not for the dependent of spirit. - Mayar, Third Keeper
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.
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.

This topic is closed to new replies.

Advertisement