Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Writing Test Cases

Posted on 2006-07-13
6
2,014 Views
Last Modified: 2008-03-10

Can you please give me a practical example of how to go about writing a test case?
0
Comment
Question by:Neesh75
6 Comments
 
LVL 7

Accepted Solution

by:
sachinwadhwa earned 84 total points
ID: 17098266
0
 
LVL 4

Assisted Solution

by:v_karthik
v_karthik earned 83 total points
ID: 17100789
>> Can you please give me a practical example of how to go about writing a test case?

For example, if you have a class (assuming you are using an object oriented language) that adds  divides 2 numbers and returns the result.. like

public float divide(int a, int b)
{
 return a/b;
}

Your test case should try to USE this method in all possible ways and see if it behaves abnormally...  like

class TestCases
{
public bool testDivide()
{
   a = 10; b = 2;  
   if( divide(a,b) == 5.0)  return true;    // test case for the normal operation of the method
   
   a = 10; b = 0;
   try {
    divide(a,b);
    // take an action
   } catch(Exception x) { // take an action }   // this case is to make sure your method acts properly when there is an illegal divide. "properly" depends on what you want it to do.

}


If you are using Java, try out JUnit. It generates a lot of cases automatically for you, and also makes neat html reports on the number of passed / failed cases.

}
}
0
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 17107239

>>Can you please give me a practical example of how to go about writing a test case?

from which perspective u r talking?
as a developer or as a tester?
test case for a white boix etsting or  black box
Functional or Performance?
0
 

Assisted Solution

by:jon1b
jon1b earned 83 total points
ID: 17206480
a test case should include one specific procedure for verifing one small and specific piece of functionality.  

So basically if you have a requirment for a wordprocessor to have the ability to save a document.  

You will want to test that if you press the save button it saves
or if you press alt +f +s it saves
or if you go to the file menu and scroll down to save it saves.  

Further more you will want to test that the document has changed  and if after you save if it comes back up with out a bunch of garbage

So Your test case should include the procedure on how to save all three ways and how to verify if the document did in fact save and didnt have a bunch of garbage in it.  
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

This story has been written with permission from the scammed victim, a valued client of mine – identity protected by request.
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
The Bounty Board allows you to request an article or video on any technical topic, or fulfill a bounty request to earn points. Watch this video to learn how to use the Bounty Board to get the content you want, earn points, and browse submitted bount…
Where to go on the main page to find the job listings. How to apply to a job that you are interested in from the list that is featured on our Careers page.

829 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