Pros and Cons of Using the C assert Macro for Unit Testing in C/C++

This is a short follow-up to my recent article A Very Simple Introduction to Unit Testing. In that article I described the development of a very simple unit test for a very simple C++ class. To do this I used the C/C++ assert() macro, saying the following about it:

"…although assert wasn’t originally intended for unit testing, it makes a simple but effective tool for doing so without the need to look outside the language’s standard library."

I’d like to thank John Crickett for - in an offline conversation - pointing out that there are some things that I should have made clearer. Although - as I said - assert is very effective for unit testing without the need to look outside the C/C++ standard library, it does have its shortcomings. Let me summarise the points for and against.

Points for:

  1. There is no need to look outside the language’s standard library, so programmers can start unit testing without the overhead of having to set anything up
  2. If an assert fails, the program stops running. Therefore, the programmer must fix the problem before continuing. Note this is also a point against (below), but the reasoning is different

Points against:

  1. It is only available to programmers working in C and/or C++ (obviously)
  2. You can only test the debug version of your code
  3. If an assert fails, the program stops running. This makes assert unsuitable for unit tests that are run in any kind of automated mode - for example, some automated build systems run the unit tests immediately after the applicable unit of code has been built

Therefore, based on the above, I suggest the use of assert is suitable for programmers unit testing in the following situations:

  • Learning to write unit tests (see 1, under points for), either as part of a formal training course or otherwise
  • Unit testing in a development environment which has no unit testing culture (again, see 1, under points for). Programmers can develop their own unit tests without the need for support from their development environment. For example, they may not be allowed to - or even able to - install libraries other than those officially used by the development group

Thinking about it now, my original assertion (pun intended) was over zealous, in that I didn’t qualify it with the context I was thinking in at the time. This article should serve to set the record straight.

The question remains: what should be used in those situations where assert is not sufficient? I was going to summarise some of the alternatives available in C++, but it now occurs to me that such a summary would really be out of place in this article. This is because - going back to its predecessor A Very Simple Introduction to Unit Testing - I only used C++ in the first place so I could use assert, and I wanted to use assert in the first place for simplicity. That is to say, the discussion here is about the suitability of assert. Therefore, I’ll take the approach of coming back to this topic soon, and write a summary of the available unit testing libraries/frameworks for several popular programming languages. When I’ve done so, I’ll post an update here with a link to it.

Leave a comment

?>Lesbian sport videos publicnude public invasion Vince Ferelli Roxy Love Big Mouthfuls tight ass drilled outinpublic Amy Reid shaved pussy hammered Charmane Star outinpublic submityourbitch.com submit your bitch hazehim Monsters Of Cock outinpublic.com publicinvasion busty adventures haze him Hot tight pussy submityourbitch submityourbitch publicinvasion public invasion itsgonnahurt Blonde round ass Kat drills ungloryhole Gia Malone magical feet outinpublic.com assparade Lesbiansportvideos TOMMYDXXX Beautiful hand job Medical Femdom collegerules.com BIGGEST ASS CRAVING publicinvasion outinpublic.com SpecialExercises collegerules submit your bitch dildo drills her pussy public invasion hottest white girls ungloryhole.com natural beautiful tits lesbian lover licks Brooke Banner Blonde gets fucked hard hazehim VISCONTITRIPLETS evanrivers MALEDIGITAL pussy licked sexy blonde petite itsgonnahurt publicinvasion lucky stud in a hot threesome college rules VINTAGEGAYLOOPS pussy covered submit your bitch Aiden Aspen Milf cravers fat juicy ass. ungloryhole camel toe porn star fucked hard publicinvasion pussy pounded Sexy big tits pornstar collegerules.com Bang Bros bangbus NEXTDOORBUDDIES facial fest Aiden Aspen hazehim.com Big Mouthfuls Ice La Fox Confession Of Married Man Alexis Fawx Special Exercises lesbian dildo drilling publicinvasion Lacey lounging smacked those asses out in public collegerules SpecialExamination CODYCUMMINGS GAy Cumshots Extrem tugjobs tugjobs CIndia Summers publicinvasion public invasion itsgonnahurt.com public invasion collegerules Special Examination college rules collegerules.com ungloryhole outinpublic NEXTDOORPASS NEXTDOORPASS amazing blowjob outinpublic.com its gonna hurt milf lessons trannyland bang pas BIGGEST ASS CRAVING outinpublic.com Stephanie Cane summer time milf facialfest fuck team five Gyno Orgasm Videos NEXTDOORHOOKUPS ungloryhole.com trannyland.com NEXTDOORMALE tug jobs Nude sport videos tranny land itsgonnahurt hazehim hazehim.com Redhead BBW bait Bus publicinvasion Bareblacking public invasion firm tits fat mature redhead MedicalFemdom Summer Bailey milfsoup GynoOrgasmVideos milfsoup public invasion college rules Licking Dick And Ass submit your bitch trannyland.com Nudesportvideos 3DS Max 8 OEM3Q 3GP Video Converterdownload acdsee manager 2009 oemred eye remover pro 1.2cheapest windows vistacheapest windows vista ultimatecheap AutoCAD 2009Vision Backup Enterprisecheap Macromedia ColdFusionnero photoshow 5 downloadadobe photoshop cs oemcoldfusion mx 7 downloadkamagra sildenafil citratekamagra generic viagraorder caverta onlinecaverta 100buy cavertatadaliscasodex 50 mg tablet