unit--, a unit test framework for C++

Discussion in 'C++' started by VvanN, Apr 15, 2006.

  1. VvanN

    VvanN Guest

    hi, fellows

    I'd like to intruduce a new unit test framework for C++
    freely available at:

    http://unit--.sourceforge.net/

    It does not need bothering test registration, here is an example

    // --- begin code ---
    #include "unit--.h"

    testSuite(MySuite);

    testCase(CompareCase, MySuite)
    {
    int x = 1;
    int y = x + 2;
    assertTrue(x < y);
    }
    // --- end code ---

    besides, unit-- is implemented entirely in std C++, thus is portable
    across different platforms and compilers
     
    VvanN, Apr 15, 2006
    #1
    1. Advertising

  2. VvanN

    Phlip Guest

    VvanN wrote:

    > I'd like to intruduce a new unit test framework for C++
    > freely available at:
    >
    > http://unit--.sourceforge.net/
    >
    > It does not need bothering test registration, here is an example


    Righteous. CppUnit mires itself in endless test registration issues, instead
    of simply using macros to achieve the Test Collector pattern.

    > // --- begin code ---
    > #include "unit--.h"
    >
    > testSuite(MySuite);
    >
    > testCase(CompareCase, MySuite)
    > {
    > int x = 1;
    > int y = x + 2;
    > assertTrue(x < y);
    > }
    > // --- end code ---


    Suppose I had two suites and wanted to run the same case over both suites?

    http://c2.com/cgi/wiki?AbstractTest

    Suppose a test case uses std::basic_string<>. How would I run the test case
    twice, once with char and again with wchar_t?

    > besides, unit-- is implemented entirely in std C++, thus is portable
    > across different platforms and compilers


    Contrarily, at error time, your editor should present the option to navigate
    to a failure, the same as syntax errors.

    --
    Phlip
    http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
     
    Phlip, Apr 15, 2006
    #2
    1. Advertising

  3. VvanN

    Dave Steffen Guest

    "Phlip" <> writes:

    > VvanN wrote:
    >
    > > I'd like to intruduce a new unit test framework for C++
    > > freely available at:
    > >
    > > http://unit--.sourceforge.net/
    > >
    > > It does not need bothering test registration, here is an example

    >
    > Righteous. CppUnit mires itself in endless test registration issues, instead
    > of simply using macros to achieve the Test Collector pattern.


    Those interested in such things might also check out the Boost unit
    test framework <http://www.boost.org/libs/test/doc/index.html>; I've
    had very good results using it.

    ----------------------------------------------------------------------
    Dave Steffen, Ph.D. Fools ignore complexity.
    Software Engineer IV Pragmatists suffer it.
    Numerica Corporation Some can avoid it.
    ph (970) 419-8343 x27 Geniuses remove it.
    fax (970) 223-6797 -- Alan Perlis
    dgsteffen at numerica dot us
     
    Dave Steffen, Apr 17, 2006
    #3
  4. VvanN

    Phlip Guest

    Dave Steffen wrote:

    > Those interested in such things might also check out the Boost unit
    > test framework <http://www.boost.org/libs/test/doc/index.html>; I've
    > had very good results using it.


    That one always squicks me out.

    Specifically, it relies on excessive test registration calls, and doesn't
    use any Test Collector, despite otherwise freely abusing macros...

    --
    Phlip
    http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
     
    Phlip, Apr 17, 2006
    #4
  5. VvanN

    VvanN Guest

    Phlip wrote:
    > VvanN wrote:
    >
    > > I'd like to intruduce a new unit test framework for C++
    > > freely available at:
    > >
    > > http://unit--.sourceforge.net/
    > >
    > > It does not need bothering test registration, here is an example

    >
    > Righteous. CppUnit mires itself in endless test registration issues, instead
    > of simply using macros to achieve the Test Collector pattern.
    >
    > > // --- begin code ---
    > > #include "unit--.h"
    > >
    > > testSuite(MySuite);
    > >
    > > testCase(CompareCase, MySuite)
    > > {
    > > int x = 1;
    > > int y = x + 2;
    > > assertTrue(x < y);
    > > }
    > > // --- end code ---

    >
    > Suppose I had two suites and wanted to run the same case over both suites?
    >
    > http://c2.com/cgi/wiki?AbstractTest
    >
    > Suppose a test case uses std::basic_string<>. How would I run the test case
    > twice, once with char and again with wchar_t?
    >

    we might consider that they are different test cases,
    but they have code in common.

    "extract method"
    (http://www.refactoring.com/catalog/extractMethod.html)
    could work for this scenario.
    assertTrue() can effect in functions invoked by a testCase

    here is an example:

    // --- begin code ---
    #include <vector>
    #include <numeric>
    #include <algorithm>
    #include "../unit--.h"

    testSuite(TemplateSuite)

    template <typename T>
    void testAlgorithms()
    {
    using namespace std;
    using namespace unit_minus;
    vector<T> ve(100, 1);
    partial_sum(ve.begin(), ve.end(), ve.begin());

    assertTrue(ve.size() > 0);
    assertTrue(1 == ve[0]);
    for (unsigned i = 1; i < ve.size(); ++i) {
    assertTrue(ve[i - 1] + 1 < ve);
    }
    }

    namespace {
    testCase(IntCase, TemplateSuite)
    {
    testAlgorithms<int>();
    }

    testCase(UnsignedCase, TemplateSuite)
    {
    testAlgorithms<unsigned>();
    }

    } // namespace
    // --- end code ---

    > > besides, unit-- is implemented entirely in std C++, thus is portable
    > > across different platforms and compilers

    >
    > Contrarily, at error time, your editor should present the option to navigate
    > to a failure, the same as syntax errors.
    >
    > --
    > Phlip
    > http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
     
    VvanN, Apr 28, 2006
    #5
  6. VvanN

    Phlip Guest

    VvanN wrote:

    > testSuite(TemplateSuite)
    >
    > template <typename T>
    > void testAlgorithms()
    > {
    > using namespace std;
    > using namespace unit_minus;
    > vector<T> ve(100, 1);
    > partial_sum(ve.begin(), ve.end(), ve.begin());
    >
    > assertTrue(ve.size() > 0);
    > assertTrue(1 == ve[0]);
    > for (unsigned i = 1; i < ve.size(); ++i) {
    > assertTrue(ve[i - 1] + 1 < ve);
    > }
    > }
    >
    > namespace {
    > testCase(IntCase, TemplateSuite)
    > {
    > testAlgorithms<int>();
    > }
    >
    > testCase(UnsignedCase, TemplateSuite)
    > {
    > testAlgorithms<unsigned>();
    > }
    >
    > } // namespace
    > // --- end code ---


    Thanks!

    One use of AbstractTest is to turn a cases' setUp() and tearDown() into an
    abstract factory. setUp() will create a different type, so a common case
    body can work across a range of types. Your code doesn't need this effect
    because your assertions are not members of the basic TestCase class.

    (Assertions are typically macros, so I mean macros are members when they use
    member variables inside them.)

    --
    Phlip
    http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
     
    Phlip, Apr 28, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    418
    Ben Pope
    Jan 11, 2006
  2. nw
    Replies:
    176
    Views:
    2,448
    Gianni Mariani
    May 8, 2007
  3. Bill David
    Replies:
    2
    Views:
    280
    Arne Vajhøj
    Jun 18, 2008
  4. Bill Mosteller
    Replies:
    0
    Views:
    239
    Bill Mosteller
    Oct 22, 2009
  5. timr
    Replies:
    2
    Views:
    177
Loading...

Share This Page