Solved

Test Cases in C/C++

Posted on 2011-03-02
5
334 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now