Menu

#9 Providing a global setup decorator for running test cases

open-postponed
nobody
5
2002-07-12
2002-03-26
No

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 )
CoUninitialize();

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.

Discussion

  • Baptiste Lepilleur

    Logged In: YES
    user_id=196852

    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.

     
  • 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
    user_id=196852

    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.

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.