Menu

HowTo :CPPUNIT to unittest MFC/UI application

2003-08-10
2003-08-18
  • Venkataramani Krishnamurthy

    Hi There
    Has anyone tried using CPPUNIT unit test tool for an MFC application? My application is MFC based and it has property sheets, property pages and dialogs. How do I use CPPUNIT for unit testing this MFC application. I understand the tool's usage for normal C++ classes like ComplexNumber, BoardGame, etc. But I would like to know how to use it with my MFC application. MFC application is also C++ based but they differ in that it involves UI components. Also, there are lots of inter dependencies between the objects. If someone can provide an example that would be excellent.

    I appreciate any feedback on this.

    Thank you very much,
    Ramani

    PS - Sorry for the duplication. I already posted this in the Help forum. I wanted to post it here too to catch everyone's attention and any possible help.

     
    • Pierre Boudreau

      Pierre Boudreau - 2003-08-10

      Your questions is not specific to CPPUnit.  It is a general problem with unit testing.  User interfaces are difficult to unit test.  The best solution I know is to design your application with testability in mind.  Some patterns like Model View Controler [GoF] enhance testability by enabling you to stub out the view class and test the other ones.  See http://www.c2.com/cgi/wiki?TestFirstUserInterfaces for several other tips on writing user interfaces test first.

      For interdependencies, you would probably find Michael Feathers' work usefull.  See http://groups.yahoo.com/group/welc/files/ for a draft of a book he is writing for working effectively with legacy code.  My advice:  MAKE YOUR CLASSES INDEPENDANT AND MAKE YOUR UI CLASSES AS THIN AS POSSIBLE.  It will save you a lot of trouble when maintaing and enhancing your application in the future.

       
    • Wolfgang Stoecher

      If you can separate the code you want to test from the GUI (I do not write unit tests for GUI-code; if your GUI-specific code is thin as suggested above, then there should be plenty of code for testing left) then you might try the following approach with three projects in one workspace:
      - the core code (lib or dll)
      - the application (an exe using the above lib or dll)
      - the unit tests (using the above lib or dll)
      With the compilation dependencies properly set, the separation into three projects will not harm your efficiency.

      Wolfgang

       

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.