Menu

How do I report errors in setUp?

Help
Anonymous
2002-06-20
2002-06-20
  • Anonymous

    Anonymous - 2002-06-20

    My setUp methods are kind of complex, and can fail.  (Perhaps that's means I'm fundamentally misunderstanding how to use CppUnit; if so, I'd appreciate someone telling me).  Anyway, I've been using CPPUNIT_ASSERT to report those failures, but there's a problem with that -- when I run the test, all I see from those failures is a message like

    There were 2 errors:
    1) test: ABREQENG-010 line: -1 <unknown> "setUp() failed"

    Naturally I'd like more information from the failure, in particular, file name, line number, and the code snippet that returned 0.  In other words, I'd like the same kind of information that I would get if the failure came from the test itself, as opposed to the setUp method.

    Now, I've found a way to do what I want, but I'm not sure it's the Right Thing.  Here it is: I simply patch TestCase.cpp, the method TestCase::run, by adding another `catch' clause to the outer `try' block (the one that contains the call to setUp).  That clause looks like this:

        catch (Exception& e) {
          Exception *copy = e.clone();
          result->addError (this, copy);

    That is,  it's identical to the first `catch' clause in the *inner* try block, except that it calls addError instead of addFailure.

    This seems to work, and CppUnit passes all its self tests, so I guess I can't have messed things up too badly.  Still, I'm uncertain that this is sensible; I'd like to hear comments from people who are more familiar with CppUnit than I am.

    Thanks.

     
    • Tom Plunket

      Tom Plunket - 2002-06-20

      What's curious is what's failing and why?

      The setUp should be doing as little as possible (IMO), and what it does should be foolproof, e.g. otherwise tested good.

      Take some time and follow the newsgroup comp.software.extreme-programming, and maybe check out the Wiki starting at http://c2.com/cgi/wiki?CodeUnitTestFirst

      Good luck.
      -tom!

       

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.