You are not logged in. Login Now
 0-3   4         
 
Author Message
cross
The Testing item Mark Unseen   Sep 17 00:17 UTC 2006

Confused about testing?  Don't know the difference between unit level,
systems, and integration testing?  Want to know more about unit testing
frameworks or how to apply them?  Ask here!
4 responses total.
remmers
response 1 of 4: Mark Unseen   Sep 18 15:15 UTC 2006

Yeah, how do you do that stuff?
other
response 2 of 4: Mark Unseen   Sep 18 20:11 UTC 2006

First, you locate and install a program which provides an integrated
development and testing environment, such as Eclipse.  Then you locate
and install the modules for whatever language you're working in.  Then
you spent a vast amount of time trying to properly configure the
environment and modules to suit the needs of your project, programming
style, available screen real estate, network structure, hardware
systems, etc.  Then you start writing code (or tests, depending on
whether you prefer test-driven development or code-driven testing) and
testing it.  Voila!
cross
response 3 of 4: Mark Unseen   Sep 19 03:42 UTC 2006

You could do that.  It needn't be so elaborate.  I found and modified
a minimal testing suite for C once that was about six lines of preprocessor
macros, and I started using it for grexsoft.  Here's my current "myunit.h"
that I use for testing C code under Unix:

/*
 * My own simple unit-testing framework.  A simplified version
 * of the minunit used on grex.
 */

#include <stdio.h>

extern int myu_ntests;
extern int myu_nfailed;

#define myuinit() \
        do { \
                myu_ntests = 0; \
                myu_nfailed = 0; \
        } while (0)

#define myuassert(test, ...) \
        do { \
                int r = (test); \
                if (!r) {  \
                        (void)fprintf(stderr, "ERROR: "); \
                        (void)fprintf(stderr, __VA_ARGS__); \
                        (void)fprintf(stderr, "\n"); \
                        return (!r); \
                } \
        } while (0)

#define myuruntest(test, ...) \
        do { \
                int r = test(__VA_ARGS__); \
                myu_ntests++; \
                if (r) myu_nfailed++; \
        } while (0)

#define myurunsuite(test) \
        do { \
                test(); \
        } while (0)

#define myureport() \
        do { \
                (void)printf("Tests run: %d, failed: %d (%2.2f%%).\n", \
                    myu_ntests, myu_nfailed, \
                   (float)myu_nfailed / (float)myu_ntests * 100.0); \
        } while (0)


Here's an example of its usage:

/*
 *  Test bit vector code.
 *
 *      $Id: bitvec_test.c,v 1.2 2005/06/03 19:22:46 cross Exp $
 *
 *  Dan Cross <cross@math.psu.edu>
 */

#include "bitvec.h"
#include "myunit.h"
int myu_ntests, myu_nfailed;

int
test_bv_get(BITVEC_T *bp, int pos, int expected)
{
        myuassert(bv_get(bp, pos) == expected, "bv_get(bp, %d) != %d", pos,
expe
cted);
        return 0;
}

int
main(void)
{
        BITVEC_T bv;

        myuinit();

        bv_init(&bv, 12);
        bv_free(&bv);

        bv_init(&bv, 33);
        bv_free(&bv);

        bv_init(&bv, 32);

        bv_set(&bv, 0);
        bv_set(&bv, 1);
        bv_set(&bv, 2);

        myuruntest(test_bv_get, &bv, 0, 1);
        myuruntest(test_bv_get, &bv, 1, 1);
        myuruntest(test_bv_get, &bv, 2, 1);
        myuruntest(test_bv_get, &bv, 7, 0);
        myuruntest(test_bv_get, &bv, 8, 0);

        bv_clr(&bv, 2);
        myuruntest(test_bv_get, &bv, 0, 1);
        myuruntest(test_bv_get, &bv, 1, 1);
        myuruntest(test_bv_get, &bv, 2, 0);
        myuruntest(test_bv_get, &bv, 64, -1);

        bv_free(&bv);

        myureport();

        return(0);
}

I used to do all of this via printf() statements combined with grep or
just eyesight, but I find this much better.  I've also used CppUnit,
check, jUnit, and a few others to good effect.

The extreme programming people have a lot of experience with this sort
of thing:

http://www.xprogramming.com/
 0-3   4         
Response Not Possible: You are Not Logged In
 

- Backtalk version 1.3.30 - Copyright 1996-2006, Jan Wolter and Steve Weiss