Designing and Implementing Test Code

This is a discussion on Designing and Implementing Test Code within the C++ Programming forums, part of the General Programming Boards category; I have searched the board and the internet with very little luck finding any good resources (ONLINE) that explain what ...

  1. #1
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317

    Designing and Implementing Test Code

    I have searched the board and the internet with very little luck finding any good resources (ONLINE) that explain what are good practices for writing test code and how to best implement it. Granted I am sure there are many books and I am heading to the bookstore tommorow. Just wanted to know if anyone can direct me to some online resources that go a little more in depth. I am not taking any college courses. I am just doing this in my spare time. I have found extensive information about Requirments Documents and Design Documentation, commenting code practices and such but very little on how to design tests to break your code.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Basically you just test the extremes. For example, if you're testing a sorting function, put your pre-sort items in the opposite order. If you're testing a function that returns the maximun number in a set, try placing it at the begining and then the last.

    Also, make test cases to test areas that you barely know works. If there is a specific code you are unsure of, test it aggresively with the aim to break it.

    This phase is kinda dumb. You should always test each component/piece of code as you go along. Its better that way.

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    uh, not writing bad code in the first place?

    the only thing I can really think of right now is to have your program accept command-line arguments and then have another program call it over and over with all kinds of arguments...

    unless you mean test data... then you might want to test the extremes, give it chars when it wants an int, or create a data file full of random values and put those through by hand (not recommended)
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317

    I am still trying to figure out what makes a good test.

    Basically I am trying to develop a sense of what makes a good test. If I am not testing anything meaningful then the results mean nothing. I guess I wasn't specific in my previous post. This is probably more of a design problem then a coding one. But then again coding is design right. I am looking for design principles. I know there is black box testing and whitebox testing but i have yet to see any code examples of each really. If I am going to craft a test, how do I do it so I maximize the number of bugs I will find? I can make inefficient tests just as well as inefficient code. Maybe it just comes with practice I dunno but I was hoping to get a better handle on the subject. It seems to be a very integral part of programming but one with very little information online. Well the web is a big place. Maybe I just haven't found it yet.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    there's no information because you have to suit your test to your program... if your program does exponents, test it with a postitive, zero, and negative exponent... if you really want to test it, give your program to somebody who doesn't know much about computers and let them play around with it for a while...

    tell us what kind of program you have and we'll suggest some tests...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    If you ever do programming competitions, you'll get good at this pretty quickly, as most of the sample data you're given is straightforward, but the data for evaluation is designed to break your program. (I know, I wrote a contest today with 3 other guys from my school)
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317

    this is just a learning sample I did

    Ok I just pulled this out of my list of learning programs it is fairly simple.

    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    
    int main()
    {
    
    	char name[50];
    	char lastname[50];
    	cout <<"Please enter your name:  ";
    	cin.getline(name,50,'\n');
    	if(!strcmpi("Alexander",name))
    	{
    		cout<<"That's my name too.\n";
    	}
    	else
    	{
    		cout<<"That is not my name.\n";
    	}
    	cout<<"What is your name in uppercase...\n";
    	strupr(name);
    	cout<<name<<"\n";
    	cout<<"And your name in lowercase...\n";
    	strlwr(name);
    	cout<<name<<"\n";
    	cout<<"Your name is "<<strlen(name)<<" letters long\n";
    	cout<<"Enter your last name:  ";
    		cin.getline(lastname,50,'\n');
    	strcat(name," ");
    	strcat(name,lastname);
    	cout<<"Your full name is "<<name<<"\n";
    
    	
    	return 0;
    }
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I have to agree with major_small and say not writing bad code...Of course this isn't always as easy as major_small makes it sound. For example, I remember I wrote some database software one time (for windows) and it used a backend written in C++ and a VB rendered GUI. Well...the VB portion caused some unexpected issues to come up when I ran it on another machine. Without boring anyone with details, testing a piece of software on another machine will do wonders for finding bugs. Especially when you are cross compiling or trying to make code that is compatible with older versions of the same OS.

  9. #9
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    How come you #include <string> when you never use the string class? For the strcmp( ) functions, its #include <cstring>.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    ^ I made that mistake alot at first too

    test ideas:
    • Names longer than 50 chars
    • spaces in names
    • strange chars in names
    • Alexander in different cases
    • 'alaxender'
    • enter an int when it wants upper/lower case
    • enter uppercase when you want lowercase
    • enter lowercase when you want uppercase
    • enter special characters only


    EDIT: I just realized it never asks for upper or lower case... it just tells you what it is... bad wording... anyway, at the end, the the string is still in lowercase, so you'll get "joe Nobody" instead of Joe Nobody"...

    also, I would go with toupper(char*) and tolower(char*)... I just haven't seen strupr and strlwr around enough... at all, actually...
    Last edited by major_small; 03-02-2004 at 10:10 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  11. #11
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317

    Sorry about that.

    I was following an example I got from a website tutorial. I guess I learn something new everday.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  12. #12
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317

    OK I got it crash

    I guess entering in extreemly long names for both the first andlast name causes a runtime error. probably a buffer overflow?
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  13. #13
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    it won't overflow the array: cin.getline(name,50,'\n');
    it stops at 50 chars... but you should still test it (watch the last name)
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  14. #14
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317

    I see where the Stcat() combines both the first and last name

    Stcat() causes the problem because you are trying to combine two
    arrays each 50 chars into one it wont' fit and you overwrite the array.



    If you want to know where I got this example it was from the tutorials on this site.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  15. #15
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    ^ nice catch...

    I wouldn't follow the tutorials on this site too closely... some of them aren't very standards-compliant and they're really in need of updating...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implementing C in html,Newbie Here
    By blondie.365 in forum C Programming
    Replies: 2
    Last Post: 10-15-2008, 08:56 AM
  2. Implementing a binary search
    By smitsky in forum C++ Programming
    Replies: 3
    Last Post: 10-06-2004, 02:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21