Menu

Using new macros in lib to run GUI/text tests

2001-05-16
2001-05-17
  • Ralph Bohnet

    Ralph Bohnet - 2001-05-16

    I would like to organize all unit tests into a lib, and then create 2 executables that link to the unit test lib:
      - GUI Test runner (like HostApp example)
      - text version to run all tests on the command line

    The unit tests use the new macros introduced in cppunit 1.5.5.

    As a proof of concept, I moved ExampleTestCase.[h,cpp]into a separate lib, then attempted to link HostApp to the new lib.  Running HostApp fails to find the tests defined in ExampleTestCase.

    Can some one explain why this doesn't work and how
    I could get it to work? It may assist if there was
    a sample of this in the examples directory.

    Environment is VC++ 6.0, SP4.

    Ralph Bohnet

     
    • Baptiste Lepilleur

      The library and the executable have different "static space". TestFactory registry use a static singleton. So the library have its one singleton and the executable have another one.

      The way around this is to get the library to publish its test suite:

      CppUnit::Test *getLibrarySuite()
      {
        CppUnit::TestSuite *suite = new CppUnit::TestSuite( "My library test" );
        TestRegistry.getRegistry().addTestToSuite( suite );
        return suite;
      }

      The implementation must not be in a header file.

      You add the library test as follow in executable:

          TestRunner  runner;
          runner.addTest ( getLibrarySuite() );

       

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.