Loading ...
Sorry, an error occurred while loading the content.

[extremeprogramming] CppUnit user's question

Expand Messages
  • Michael C. Feathers
    How do you all feel about the way test methods are added in the framework? Java, (lucky for itself) has reflection, so test methods can be gleaned from classes
    Message 1 of 1 , Jan 28, 2000
    • 0 Attachment
      How do you all feel about the way test methods
      are added in the framework?

      Java, (lucky for itself) has reflection, so test
      methods can be gleaned from classes and
      added to suites automatically. In CppUnit,
      you have to write the test method and add it to
      the suite method manually.

      For a while, I've been thinking about adding
      macros to the distribution, something like
      the following (uncompiled, so be easy on me):


      #define BEGINTEST(Case,Fixture) \
      class Case : public Fixture { \
      protected void runTest ()


      #define ENDTEST (Case, Fixture)\
      } \
      } ___Fixture##Case (#Case);


      class TestCase : public Test
      {
      public: TestCase () { suite.addTest (this); }
      protected: static TestSuite suite;
      public: static Test *suite () { return &suite; }
      };

      So.. you could do something like:


      class DateTest : public TestCase
      {
      public:
      ...
      void setUp () { m_date = new Date; m_includedDate = new Date; ... }
      void tearDown () { delete m_date; ... }

      protected:
      Date *m_date;
      Date *m_includedDate;
      ...

      };

      BEGINTEST(Includes,DateTest)
      assert (!m_date->includes (m_excludedDate);
      assert (m_date->includes (m_includedDate);

      ENDTEST(Includes,DateTest)


      It could even go baroque by making macros
      to do this.

      BEGINFIXTURE (DateTest)
      Date *m_date;
      ...
      SETUP
      m_date = new Date; ...
      TEARDOWN
      delete m_date;
      ENDFIXTURE (DateTest)

      It would be probably be better to do the test
      add in the BEGINTEST macro since it
      always defines a leaf class. Back in the
      TestCase class it could cause problems
      if fixtures are inherited.

      I have a real love/hate relationship
      with this sort of thing. Sometimes
      its good to hide all of this and
      sometimes its bad.

      Running subsets of unit tests, for
      instance, gets tougher. But,
      another set of macros could be
      used to prune and sort the global
      list of tests.

      Comments?

      Michael



      ---------------------------------------------------
      Michael Feathers mfeathers@...
      Object Mentor Inc. www.objectmentor.com
      Training/Mentoring/Development
      -----------------------------------------------------
      "You think you know when you can learn, are more sure when
      you can write, even more when you can teach, but certain when
      you can program. " - Alan Perlis
    Your message has been successfully submitted and would be delivered to recipients shortly.