Solved

Test Cases in C/C++

Posted on 2011-03-02
5
343 Views
Last Modified: 2012-06-22
Can I get some links / resources that talk about writing test cases in C/C++

Thanks!
0
Comment
Question by:dshrenik
  • 2
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
phoffric earned 250 total points
ID: 35022928
System Test Cases deal with testing the requirements specification. These tests are usually black box testing. System testing often includes stress testing which puts "a greater emphasis on robustness, availability, and error handling under a heavy load,"
   http://en.wikipedia.org/wiki/Stress_testing
And it also includes capacity testing which in some companies means to test the maximum performance requirements for which the system runs smoothly without any need for error handling.

When writing requirements, care should be taken to be sure that each requirement can be tested without heroic efforts, since that could result in a test not being written. What good is a requirement if you cannot test it?

There are many other forms of testing that are important. Here is an article on Code Coverage Analysis which is usually necessary in unit testing to satisfy many customers:
  http://www.bullseye.com/coverage.html 

"With white-box testing, you must run the code with predetermined input and check to make
sure that the code produces predetermined outputs. Often programmers write stubs and
drivers for white-box testing. A driver is a software module used to invoke a module under
test and, often, provide test inputs, control and monitor execution, and report test results
(IEEE, 1990) or most simplistically a line of code that calls a method and passes that method
a value."
     http://agile.csc.ncsu.edu/SEMaterials/WhiteBox.pdf

This paper uses UML Activity Diagrams for scenario based white box testing.
    http://dspace.nitrkl.ac.in:8080/dspace/bitstream/2080/833/1/biswal.pdf

All my projects used UML Sequence Diagram Scenario white box testing (using CPPUnit Test).
    http://www.stickyminds.com/sitewide.asp?Function=edetail&ObjectType=ART&ObjectId=3718


Some Test Case Tools:
  cunit:
    http://cunit.sourceforge.net/

  cppunit:
    http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page

  boost testing:
    http://www.boost.org/doc/libs/1_44_0/libs/test/doc/html/utf.html 
0
 
LVL 12

Assisted Solution

by:trinitrotoluene
trinitrotoluene earned 250 total points
ID: 35032527
There's a world of tools out there and you could get lost in the jungle. If you have the time take a look at the article below

http://gamesfromwithin.com/exploring-the-c-unit-testing-framework-jungle

Apart from that I would also recommend that you take a look at

TUT

WinUnit and ofcourse

CUTEE
0
 

Author Comment

by:dshrenik
ID: 35032670
I don't want to use any tools. I want to write my own code for testing. Any tutorials on those lines?

Thanks!
0
 
LVL 32

Assisted Solution

by:phoffric
phoffric earned 250 total points
ID: 35032737
>>  I want to write my own code for testing.
You can download existing code and adapt it to your needs.

CUnit:
CUnit-2.1-2-src.tar.bz2 has source code, documentation, and examples for automated testing. Download here:
     http://sourceforge.net/projects/cunit/files/CUnit/2.1-2/CUnit-2.1-2-src.tar.bz2/download

CPPUnit:
cppunit-cvs-repo-archive.tar.bz2 has source code, documentation, and examples.
         http://sourceforge.net/projects/cppunit/files/SVN%20Migration%20Archive/cppunit-cvs-repo-archive.tar.bz2/download

The documentation and examples should serve as a tutorial for you.
0
 
LVL 12

Assisted Solution

by:trinitrotoluene
trinitrotoluene earned 250 total points
ID: 35032768
yes I understand that. That's the reason I'm suggesting you take a look at TUT. It is not a library per se and it only has header files which will assist you in writing your own unit tests.

You could ofcourse write your own unit tests by adding in some test functions written in C++. These could co-exist with your code and all you would need to do is just use a compile switch which would either turn on or turn off the function.

So when you are in the Development phase just compile these functions and when you are ready to release turn off the switch so that you don't compile the functions into the build.

Here's an article about how to approach the task of writing unit tests.
http://www.codeproject.com/KB/architecture/FirstUnitTest.aspx

My suggestion ofcourse is this : Don't re-invent the wheel when its already there.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question