General question on regression/unit testing in C - Linux

This is a discussion on General question on regression/unit testing in C - Linux ; Hi, I have an application written in C and I want to build a test suite for it. My intention is to test the application's functions individually, by calling them with random input from some test code, and look for ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: General question on regression/unit testing in C

  1. General question on regression/unit testing in C

    Hi,

    I have an application written in C and I want to build a test suite for
    it. My intention is to test the application's functions individually,
    by calling them with random input from some test code, and look for
    expected output - really an ordinary testing situation. Also I want to
    keep the test code external to the application sources, (e.g. at least
    the test logic would be in separate project and sources not to clutter
    the application sources.)

    The problem is, the functions that are test subjects are in the
    application's project, and they refer to certain include files that
    define certain variables the test would want to override. (e.g. a range
    value that is defined in a header file, but the test would like to
    define that itself.)

    The question is what would be the most convenient way to build such a
    test suite?
    I could think of two possibilities:
    1-) perhaps copy some of the application's source files into the test
    project and strip the unwanted bits with a script. This would be
    tedious if I wanted to test many functions.

    2-)Define in the test suite, all the include files that an application
    source file includes, and use the test suite include path as the first
    path in -I in gcc commandline, so the application's headers would be
    overridden.

    Any opinions, example projects doing similar?

    Thanks,
    Bahadir


  2. Re: General question on regression/unit testing in C

    Bahadir,

    test suite is usually a part of the project itself, which makes perfect
    sense, since you always want to be able to run tests as you modify the
    project sources.

    Create a subdirectory in your source code directory tree and make it
    part of the project. This avoids all the problems you may have with
    either technique you mention, by giving the test programs direct access
    to actual include files and libraries within your project.

    Usually, utilizing this approach, there is a make target called test,
    which runs your test suite on current version of project, anytime you
    like, to ensure recent modifications didn't break things.

    Test suites held appart from the souce code are OK for things like
    application interface or specification conformance tests, where these
    may be run against more than one implementation.

    Take look at , where a number of
    testing tools and framework is listed.

    Regards,
    Jan

    On Oct 19, 10:59 am, Bilgehan.Bal...@gmail.com wrote:
    > Hi,
    >
    > I have an application written in C and I want to build a test suite for
    > it. My intention is to test the application's functions individually,
    > by calling them with random input from some test code, and look for
    > expected output - really an ordinary testing situation. Also I want to
    > keep the test code external to the application sources, (e.g. at least
    > the test logic would be in separate project and sources not to clutter
    > the application sources.)
    >
    > The problem is, the functions that are test subjects are in the
    > application's project, and they refer to certain include files that
    > define certain variables the test would want to override. (e.g. a range
    > value that is defined in a header file, but the test would like to
    > define that itself.)
    >
    > The question is what would be the most convenient way to build such a
    > test suite?
    > I could think of two possibilities:
    > 1-) perhaps copy some of the application's source files into the test
    > project and strip the unwanted bits with a script. This would be
    > tedious if I wanted to test many functions.
    >
    > 2-)Define in the test suite, all the include files that an application
    > source file includes, and use the test suite include path as the first
    > path in -I in gcc commandline, so the application's headers would be
    > overridden.
    >
    > Any opinions, example projects doing similar?
    >
    > Thanks,
    > Bahadir



  3. Re: General question on regression/unit testing in C

    Have a glance at http://cunit.sourceforge.net/

    ABAI
    Bilgehan.Balban@gmail.com wrote:
    > Hi,
    >
    > I have an application written in C and I want to build a test suite for
    > it. My intention is to test the application's functions individually,
    > by calling them with random input from some test code, and look for
    > expected output - really an ordinary testing situation. Also I want to
    > keep the test code external to the application sources, (e.g. at least
    > the test logic would be in separate project and sources not to clutter
    > the application sources.)
    >
    > The problem is, the functions that are test subjects are in the
    > application's project, and they refer to certain include files that
    > define certain variables the test would want to override. (e.g. a range
    > value that is defined in a header file, but the test would like to
    > define that itself.)
    >
    > The question is what would be the most convenient way to build such a
    > test suite?
    > I could think of two possibilities:
    > 1-) perhaps copy some of the application's source files into the test
    > project and strip the unwanted bits with a script. This would be
    > tedious if I wanted to test many functions.
    >
    > 2-)Define in the test suite, all the include files that an application
    > source file includes, and use the test suite include path as the first
    > path in -I in gcc commandline, so the application's headers would be
    > overridden.
    >
    > Any opinions, example projects doing similar?
    >
    > Thanks,
    > Bahadir



+ Reply to Thread