Menu

step by step tutorial??

Help
Anonymous
2003-07-13
2003-07-14
  • Anonymous

    Anonymous - 2003-07-13

    Hi!

    Is there anybody who could give me a step by step tutorial to working with cppunit 1.8 under linux (or cygwin/windows)?
    I've been trying to get along with several examples I've found (cookbook etc.) - but unsuccessfully :-(

    I would be very grateful for any help!

     
    • Hisakuni Kitahara

      if you just run your test cases, try following sample on linux.

      [runTest.cpp]
      #include <iostream>
      #include <string>
      #include <iomanip>
      #include <cppunit/ui/text/TestRunner.h>
      #include <cppunit/TextOutputter.h>
      #include <cppunit/CompilerOutputter.h>
      #include <cppunit/extensions/TestFactoryRegistry.h>

      int main(int argc, char* argv[]) {
          bool toStdErr = false;
          for ( int i = 1; i < argc; ++i ) {
              std::string arg(argv[i]);
              if ( arg == "--cerr"      ) toStdErr = true;
          }
          CppUnit::TextUi::TestRunner runner;

          runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());

          CppUnit::Outputter* outputter = 0;
          std::ostream* stream = toStdErr ? &std::cerr : &std::cout;

          outputter = new CppUnit::TextOutputter(&runner.result(),*stream);
          runner.setOutputter(outputter);
          bool result;
          result = runner.run();
          std::cerr << std::endl;
          return result ? 0 : 1;
      }
      **************************************
      [YourTest.cpp]
      #include <cppunit/extensions/HelperMacros.h>
      #include <cppunit/TestAssert.h>

      class YourTest : public CppUnit::TestFixture {
          // you also need sync the classname at the last line of file.
          CPPUNIT_TEST_SUITE(YourTest);
      // begin registration of test case.
          CPPUNIT_TEST(testCase1);
          CPPUNIT_TEST(testCase2);
      // end of registration.
          CPPUNIT_TEST_SUITE_END();
      public:
          virtual void setUp()
          {
          }
          virtual void tearDown()
          {
          }

      // implementation of test cases.
          void testCase1()
          {
              CPPUNIT_FAIL("not implemented");
          }
          void testCase2()
          {
              CPPUNIT_FAIL("not implemented");
          }
      };

      // Do not forget to sync the class name.
      CPPUNIT_TEST_SUITE_REGISTRATION(YourTest);

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.