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

Re: [XP] Test Objectives (was: Re: Unit Test Challenge II)

Expand Messages
  • Kevin Lawrence
    From: Bryan Dollery [snip] ... [snip] ... Our product contains APIs that are used by third party developers. We use
    Message 1 of 263 , Apr 1, 2002
      From: "Bryan Dollery" <Bryan.Dollery@...>

      [snip]
      >
      > This isn't rhetorical - I've never understood the place of assertions in a
      > unit-testing paradigm.
      >
      > Are the assertions doing something different from unit-tests? You say here
      > that they are just documenting preconditions - but it's not true, because
      > documents are passive, and these are active. You also say:
      >
      > > We do a lot of testing with both "non-production" code and "production
      > > code", so we're pretty comfortable with assertions being
      > > stripped out of the
      > > final "production" version.
      >
      > Which tells me that the assertions are used as a tool to assist you in
      > development. I can see no difference in their use from unit-tests in this
      > context, but if this is right then there are many reasons to prefer unit
      > tests over assertions.
      >

      [snip]

      >
      > Honestly, I'm confused by this whole assertion thing (yes, I know exactly
      > what they are, and how to use them, in many different languages [well, at
      > least four]). Can you, or anyone, throw some light on this for me.
      >

      Our product contains APIs that are used by third party developers. We use
      assertions of this form ...

      /**
      * @param arg must not be null
      */
      public void doSomething(String arg){
      Assertion.isNotNull(arg);
      // more stuff
      }

      ... quite a lot - as well as more complex assertions. We also test for the
      assertions...

      public void testDoSomethingAssertion(){
      try {
      target.doSomething(null);
      }
      catch(AssertionException ae){
      assertEquals("ASSERT: Value was null", ae.getMessage());
      }
      }

      quite a lot. We don't test the javadoc comments. The assertions ship with
      the production code.

      Incidently, in a different incarnation, I use the .NET libraries a lot and I
      have found the assertions in those libraries very helpful. My product in
      this incarnation does not have APIs and I find myself relying on my own
      assertions less and less. I suspect this is more through lazyness than a
      conscious effort to eliminate them. So far it has not bitten me.

      BTW I am not prescribing one approach or the other - I am just trying to
      describe what has worked for me.

      Kevin
    • Ilja Preuß
      ... I don t write many asserts or comments, but *I* would most often prefer asserts before comments because - I always first look at the code if I want to know
      Message 263 of 263 , Apr 6, 2002
        > Why don't you replace the asserts with comments?

        I don't write many asserts or comments, but *I* would most often prefer
        asserts before comments because

        - I always first look at the code if I want to know what it does. If a
        precondition is significant enough to be written down, it is probably
        significant enough to be spotted early.

        - I most often find it easier to articulate something about code *in*
        code than in natural language.

        - I think if I *don't* find it easy to articulate a significant concept
        about the code in code, that tells me something about the design.

        - Even if I find it easy to articulate an assertion, writing it down
        might nevertheless tell me something about the design I didn't smell
        before.

        - I almost always find it easier to understand code than to understand
        natural language.

        - I am more likely to forget adjusting a comment to changing code than
        adjusting an assert.

        - I think it is easier to refactor an assertion than to refactor a
        comment

        - I simply hate writing comments, whereas I love writing code! ;-)

        There are probably more reasons...

        Regards, Ilja
      Your message has been successfully submitted and would be delivered to recipients shortly.