#9 Providing a global setup decorator for running test cases


Since the MFC TestRunner runs each test on a separate
thread, the COM components that I was trying to test
were failing because CoInitialize was not called for
the thread that separate thread.

My fix was simple. Just call CoInitialize and
CoUninitialize in ActiveTest::threadFunction:

// Simple execution thread. Assuming that an
ActiveTest instance
// only creates one of these at a time.
UINT ActiveTest::threadFunction (LPVOID thisInstance)
ActiveTest *test = (ActiveTest *)thisInstance;

bool comInit = SUCCEEDED( CoInitialize( NULL ) );

test->run ();
test->m_runCompleted.SetEvent ();

if ( comInit )

return 0;

This works for me because my components are STA but a
more general solution is needed to handle testing in
other threading models. Perhaps by passing in some
parameters to the TestRunner constructor.


  • Baptiste Lepilleur

    Logged In: YES

    I aware of that problem. This will be adressed in a future
    release by providing a global 'setup decorator' when
    running test.

    In the meantime, you can either use a common base class for
    all your test that require CoInitialize, or use the text
    mode test runner.


  • Baptiste Lepilleur

    • labels: 408845 -->
    • assigned_to: blep --> nobody
    • summary: CoInitialize not called on new thread --> Providing a global setup decorator for running test cases
    • status: open --> open-postponed
  • Baptiste Lepilleur

    Logged In: YES

    It is now possible to provide TestListener to do some global
    set up, but the MFC TestRunner still need to be reworked to
    support this feature.

  • Baptiste Lepilleur

    • labels: --> System - Writing TestCase

Log in to post a comment.