RSS

DocTest++ – Extracting test cases embedded in Source Files

31 May

UnitTest++ is brilliant in how it lets you structure and manage your tests cases but it still requires a “focus-switch”.  As I am writing a function, I should be writing a test for it, but going to another file (or compilation unit for the technical term) makes me loose focus of where I am and what I was doing.  Clearly I am only mortal and this doesnt apply to the uber coder gods out there.  And this is where python’s doctest is awesome.  Then and there test insertion (yes they are validated at a different phase but atleast you can see what tests are around).  Not to mention more info on the documentation.  After all tests cases as documentation are a pretty powerful idea.

So it hit me.  Why not doctests for C++.  Lo behold DocTest++.  Wrote this last weekend because out of laziness I was’nt really adding test cases to my mango code, as much I should.  Mango certainly does have a few unit tests (and growing rapidly) and even more certainly has no plans to replace those unit tests.  But why not doctests as well?  So DocTest++ extracts tests embedded with C/C++ code and creates test cases for them.  More at the project page on git hub for how it works and what it does.

And to go a step further, this is part of the build process in my make file. A target XXX.test.cpp is (automatically) added for file XXX that contains the @test tag.  This gets compiled along with all tests.  More importantly if any of the files change or new @test tags are added, these are picked by the build system.  Wooot!

Any improvements or feedback?

Advertisement
 

About Sri

I am a technologist, an entrepreneur, a violinist and a family man (in no particular order). My passion for software started when I was 13 - I was donated a really really old 8086 when my family migrated to Melbourne (from India). Amazing how that act of generosity changed my life. Professionally Ive been developing software for the last 15 years using a combination, C, C , Java and Python. Last few years I have been mainly involved in a combination of web backed mobile application development and am currently the co-founder of a stealth-mode startup. I started learning Carnatic violin (indian classical) for the last 10 years almost accidentally and am only kicking myself for not getting into it earlier. Hopefully one day I would be doing a lot more of it. Loves - My wife, family and all things technology, entrepreneurship and indian classical music. Gets Annoyed By - Recruiters who think knowing X makes you incapable of doing Y (examples of such X-Y pairs include - C and C, iPhone and Android, Django and Ruby, Postgres and MySQl, etc),
Leave a comment

Posted by on May 31, 2010 in C++

 

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.