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

Re: [XP] use of exeptions for UnitTest asserts

Expand Messages
  • Tammo Freese
    ... No! The cause of the failure is the FIRST assertion. Fix it, then go on. (If you have more than one assertion in a test method, the test will be aborted
    Message 1 of 3 , Apr 3 7:36 AM
      At 08:15 30.03.00 +0100, you wrote:
      >Hi there!
      >
      >I use CppUnit and looked at JUnit.
      >
      >A UnitTest throws an exception if an assertion fails. So when the first
      >assertion fails, the whole UnitTest is aborted.
      >Often a UnitTests has several asserts. You exercise some code and then
      >test several conditions. It would often be helpfull to see all the asserts
      >that fail. As you get more information, this points you more directly to
      >the cause of the failure.

      No! The cause of the failure is the FIRST assertion. Fix it, then go
      on.

      (If you have more than one assertion in a test method, the test will be
      aborted
      after the first assertion that fails. And this is very good, because in
      most cases
      the following assertions do not make sense. If you want to read data from a
      stream and opening (e.g. the first assertion) fails, the second assertion
      (e.g. the
      first element read from the stream is correct) will surely fail because
      the stream was not opened. The functionality you request would be very
      annoying
      since a test would throw a bunch of failures and errors which could be
      fixed by
      fixing the first one.)

      If you have situations where the next assertions would be interesting to know,
      it is possible that the tested method has more than one functionality. If this
      is the case, you should extract one of the functionalities in a separate
      method
      (extract method).

      >Or are my UnitTests not very good if I have this problem?
      No, this is OK.

      >Do you think it's a good idea?
      >How could it be realized?
      If it was possible to use extract method, you could test the methods
      separately and so you
      get the results you wanted to have.


      Tammo

      Dipl.-Inform. Tammo Freese
      OFFIS
      Geschäftsprozessmodellierung und Referenzmodelle
      Escherweg 2 - 26121 Oldenburg - Germany
      Fon: +49 4 41 97 22- 282 - Fax: +49 4 41 97 22- 1 02
      E-Mail: tammo.freese@... - URL: http://www.offis.de
    Your message has been successfully submitted and would be delivered to recipients shortly.