Menu

Test + GUI based tests

2002-03-12
2002-03-19
  • Philippe Lavoie

    Philippe Lavoie - 2002-03-12

    In the current cppunit 1.6.2 under windows, I can create a GUI version or a text version. Is it possible to have both for the same tests ?

    Or I'm missing something obvious which hopefully someone will point me toward right away :)

    Phil

     
    • Baptiste Lepilleur

      Yes, you can. Here is how I run post-build self testing on an MFC application (for 1.7.3, but can be easily adapted to other):

      // XtlTest.cpp : Defines the class behaviors for the application.
      //

      #include "stdafx.h"
      #include <msvc6/testrunner/TestRunner.h>
      #include <cppunit/TextTestRunner.h>
      #include <cppunit/TextTestResult.h>
      #include <cppunit/CompilerOutputter.h>
      #include "Suites.h"
      #include "XtlTest.h"

      class XtlTestApp : public CWinApp
      {
      [....]
      private:
        void runGuiTests();
        void runBuildTest();
        bool isBuildTest();
       
        int _exitErrorCode;
      };

      #ifdef _DEBUG
      #define new DEBUG_NEW
      #undef THIS_FILE
      static char THIS_FILE[] = __FILE__;
      #endif

      /////////////////////////////////////////////////////////////////////////////
      // XtlTestApp

      BEGIN_MESSAGE_MAP(XtlTestApp, CWinApp)
          //{{AFX_MSG_MAP(XtlTestApp)
          //}}AFX_MSG
          ON_COMMAND(ID_HELP, CWinApp::OnHelp)
      END_MESSAGE_MAP()

      /////////////////////////////////////////////////////////////////////////////
      // XtlTestApp construction

      XtlTestApp::XtlTestApp()
          : _exitErrorCode( 0 )
      {
      }

      /////////////////////////////////////////////////////////////////////////////
      // The one and only XtlTestApp object

      XtlTestApp theApp;

      /////////////////////////////////////////////////////////////////////////////
      // XtlTestApp initialization

      BOOL
      XtlTestApp::InitInstance()
      {
          AfxEnableControlContainer();

          // Standard initialization

      #ifdef _AFXDLL
          Enable3dControls();            // Call this when using MFC in a shared DLL
      #else
          Enable3dControlsStatic();    // Call this when linking to MFC statically
      #endif

        if ( isBuildTest() )
          runBuildTest();
        else
          runGuiTests();

          // Since the dialog has been closed, return FALSE so that we exit the
          //  application, rather than start the application's message pump.
          return FALSE;
      }

      int
      XtlTestApp::ExitInstance()
      {
          CWinApp::ExitInstance();
        return _exitErrorCode;
      }

      void
      XtlTestApp::runGuiTests()
      {
        TestRunner runner;
        runner.addTest( Suite::getAllTestsSuite() );

        runner.run();
      }

      void
      XtlTestApp::runBuildTest()
      {
        _exitErrorCode = 1;

        CppUnit::TextTestRunner runner;
        runner.addTest( Suite::getAllTestsSuite() );
        runner.setOutputter(
            CppUnit::CompilerOutputter::defaultOutputter( &runner.result(),
                                                          std::cerr ) );
        bool sucess = runner.run( "", false );
        _exitErrorCode = sucess ? 0 : 1;
      }

      bool
      XtlTestApp::isBuildTest()
      {
        if ( __argc < 2 )
          return false;
        CString argv( __argv[1] );
        return argv == "-selftest"; // flag -selftest on command line to run the text output
      }

       
    • Philippe Lavoie

      Philippe Lavoie - 2002-03-19

      Thanks, I'll give your answer a try.

      Automated builds, here I come! :)

       

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.