CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009
    Posts
    3

    Generate test cases

    Hi,

    I think the title says most of it, but just in case: I've been searching through internet, and different sites, but I could not find what I was looking for, so I was hoping, someone could help me out here:
    I have a simple C++ function (written in devcpp if this information is relevant), and I would like some test cases to be automatically generated. So I'm looking for a tool that could make this for me (I could easily write the test cases myself, since the code is just a few dozen lines long, but that's not what I'm asked for), works under windows, and preferably easy to use.

    Thanks in advance for any help.

  2. #2
    Join Date
    Oct 2006
    Posts
    616

    Re: Generate test cases

    Are your test-cases designed to pass only valid values to the function or you want to test abuse of the function interface - e.g. passing pointers to wrong objects or numbers out of the required range ?

    If you don't have defined pre-conditions on the input, and post conditions on the output - then auto-generation of test cases is a very difficult (unfeasible ?) problem.

    Coding a function is like writing a contract between you - the function author and any programmer that will use this function.
    C++ supplies some macro's for upholding contracts. See this link on Design By Contract, for example.
    If you properly define the contract's pre conditions & post conditions, then you can detect contract breaches at compile time or at run-time.
    Other languages, such as Java have tools that can auto-generate tests from the Functional Contracts, but I don't know of any tool that does that for C++.

    Regards,
    Zachm

  3. #3
    Join Date
    Jun 2009
    Posts
    3

    Re: Generate test cases

    Quote Originally Posted by Zachm View Post
    Are your test-cases designed to pass only valid values to the function or you want to test abuse of the function interface - e.g. passing pointers to wrong objects or numbers out of the required range ?
    The only requirement I expect test cases to be fulfilling, that they should be integers, because the function covers the whole reange of that data type.

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,610

    Re: Generate test cases

    You might find this article of interest
    http://alexott.net/en/cpp/CppTestingIntro.html
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.2.1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured