LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-09-2010, 02:34 PM   #1
gregarion
Member
 
Registered: Jan 2010
Posts: 69

Rep: Reputation: 15
Understanding of CppUnit


Hey guys, i am working on a simple project which incorperates some unit testing and i been trying to find some good read up about CppUnit which has good examples but its been quite hard to find. Anybody know any good links, tutorials or examples which can be of help to a beginner like me?
 
Old 01-09-2010, 02:40 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Have you looked at the cook book or do you mean how to write good unit tests?

If you are looking for good examples of writing tests then ignore what you see in the cook book. For example the first test at the top of the page is awful.
Code:
class ComplexNumberTest : public CppUnit::TestCase { 
public: 
  ComplexNumberTest( std::string name ) : CppUnit::TestCase( name ) {}
  
  void runTest() {
    CPPUNIT_ASSERT( Complex (10, 1) == Complex (10, 1) );
    CPPUNIT_ASSERT( !(Complex (1, 1) == Complex (2, 2)) );
  }
};
function name: runTest
What test!! You should always give a unit test a good name to help in identifying the problem in the compiler output, or xml if that is the way you are inclined yet this defeats TDD. If you can not think of a good name then it is generally a test smell that it is doing too much.
I like Roy Osherove's naming convention
Quote:
methodUnderTest_scenario_expectedResult
Generally only have one assert per test. A unit test has three actions:
  • setup
  • assert
  • tear down.
If the above example worked on the same instance then compare object types. Note some times these action are referred to using different names and acronyms.

Magic numbers. What is so special about 10,1,2 ? Use constants or if you must use 0 and 1 to help show to a user they have no special value.

Here is a kata cast I did after a couple of tries, there are mistakes in it yet you may learn something from watching it.

Last edited by dmail; 01-09-2010 at 05:51 PM. Reason: added link to kata
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help understanding this PostCode Linux - Newbie 3 11-09-2007 04:12 PM
CppUnit for DOS??? paulsm4 Programming 1 07-11-2007 08:45 AM
help understanding ln dr_zayus69 Linux - General 3 01-14-2005 08:33 PM
A better understanding! nny0000 Slackware 1 04-14-2004 12:01 PM
Understanding X?? nny0000 Linux - General 2 02-25-2004 02:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration