Loading ...
Sorry, an error occurred while loading the content.

138625Re: [XP] Re: Group vote for C unit testing framework

Expand Messages
  • John A. De Goes
    Feb 4, 2008
    • 0 Attachment
      UnitTest++ is far superior to any other C++ unit testing framework
      I've looked at. A simple examples suffices:

      // test.cpp
      #include <UnitTest++.h>

      TEST(FailSpectacularly)
      {
      CHECK(false);
      }

      int main()
      {
      return UnitTest::RunAllTests();
      }

      Suites and fixtures are supported and are as lightweight as the above.

      John A. De Goes
      N-BRAIN, Inc.
      http://www.n-brain.net
      [n minds are better than n-1]

      On Feb 4, 2008, at 10:24 AM, Tim Ottinger wrote:

      > By the way, I posted VIM macros quite a while back so that you don't
      > even have to scroll to the top of the file to register your functions.
      > I don't have to muck about three times in three places. I have only
      > two places (no .h file) and the editor handles one of them.
      >
      > http://blog.objectmentor.com/articles/2007/05/03/cppunit-and-vim
      >
      > example:
      > -----------------------------
      >
      > //////////////////////////////////////////////////////////////////////////////
      > // testRecordParser.cc
      > //////////////////////////////////////////////////////////////////////////////
      > #include <iostream>
      > #include <fstream>
      > #include <string>
      > #include <list>
      > using namespace std;
      > #include <cppunit/TestFixture.h>
      > #include "cppunit/extensions/HelperMacros.h"
      >
      > #include "RecordParser.hh"
      >
      > class EmptyStringToParse: public CPPUNIT_NS::TestFixture {
      >
      > CPPUNIT_TEST_SUITE(EmptyStringToParse);
      > CPPUNIT_TEST(eatWhiteSpaceDoesntCrash);
      > CPPUNIT_TEST(returnWordDoesntDie);
      > CPPUNIT_TEST(returnQuotedStringDoesntDie);
      > CPPUNIT_TEST(parserKnowsItIsEmpty);
      > CPPUNIT_TEST_SUITE_END();
      >
      > RecordParser *parser;
      > public:
      > void setUp() {
      > parser = new RecordParser("");
      > }
      > void tearDown() {
      > delete parser;
      > }
      > protected:
      > void eatWhiteSpaceDoesntCrash() {
      > parser->eatWhiteSpace();
      > }
      > void returnWordDoesntDie() {
      > CPPUNIT_ASSERT_EQUAL(string(""), parser->returnWord());
      > }
      > void returnQuotedStringDoesntDie() {
      > CPPUNIT_ASSERT_EQUAL(parser->returnQuotedString(),string(""));
      > }
      > void parserKnowsItIsEmpty() {
      > CPPUNIT_ASSERT_EQUAL(true, parser->isEmpty() );
      > }
      > };
      > CPPUNIT_TEST_SUITE_REGISTRATION(EmptyStringToParse);
      >
      > class UnquotedStringsForInput: public CPPUNIT_NS::TestFixture {
      > CPPUNIT_TEST_SUITE(UnquotedStringsForInput);
      > CPPUNIT_TEST(isNotConsideredEmpty);
      > CPPUNIT_TEST(getsCorrectFirstWord);
      > CPPUNIT_TEST(getsNoQuotedString);
      > CPPUNIT_TEST_SUITE_END();
      >
      > RecordParser* parser;
      > public:
      > void setUp() {
      > parser= new RecordParser("unquoted string");
      > }
      > void tearDown() {
      > delete parser;
      > }
      > private:
      >
      > void isNotConsideredEmpty() {
      > CPPUNIT_ASSERT_EQUAL(parser->isEmpty(), false);
      > }
      >
      > void getsCorrectFirstWord() {
      > string expected("unquoted");
      > string actual = parser->returnWord();
      > CPPUNIT_ASSERT_EQUAL(actual,expected);
      > }
      > void getsNoQuotedString() {
      > string expected = "";
      > string actual = parser->returnQuotedString();
      > CPPUNIT_ASSERT_EQUAL(actual,expected);
      > }
      > };
      > CPPUNIT_TEST_SUITE_REGISTRATION(UnquotedStringsForInput);
      >
      > ... and on and on we go....
      >
    • Show all 19 messages in this topic