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

Re: using try catch in testXXX()

Expand Messages
  • ericheikkila
    Oh...so that ll throw any uncaught exceptions up and fail on it s own? SWEET! THANKS! :) -Eric ... a
    Message 1 of 9 , Dec 1, 2002
    View Source
    • 0 Attachment
      Oh...so that'll throw any uncaught exceptions up and fail on it's own?

      SWEET!

      THANKS! :)

      -Eric

      --- In junit@y..., "J. B. Rainsberger" <jbr@d...> wrote:
      > So said ericheikkila on 2002-11-30
      >
      > >I did this just yesterday doing a little spike test with LDAP.
      > <snip />
      >
      > >Once I saw what was happening, I discovered what exception was
      > >actually being thrown and turned it into something like:
      > >
      > >public void testConnectionWithClearTextPassword() {
      > > try {
      > > // misc connection code here -
      > > // more code here
      > >
      > > fail("Should have thrown an exception here");
      > > }
      > > catch (AuthenticationException ae) {
      > > // Should come into here since clear text passwords are
      > > // not allowed.
      > > }
      > > catch (Exception e) {
      > > log.error("Exception : ", e);
      > > fail("Should have thrown an AuthenticationException");
      > > }
      > >}
      > >
      > >Anyway...I hope that demonstrates examples of both 'a sign of code
      > >that we don't quite know what it does' and why you'd want to have
      a
      > >try...catch block in a test.
      >
      > It is an excellent example, but I would continue to this:
      >
      > public void testConnectionWithClearTextPassword() throws Exception {
      > try {
      > // misc connection code here -
      > // more code here
      >
      > fail("Should have thrown an exception here");
      > }
      > catch (AuthenticationException ae) {
      > // Should come into here since clear text passwords are
      > // not allowed.
      > }
      > }
      >
      > J. B. Rainsberger,
      > President, Diaspar Software Services
      > Let's write software that people understand.
      > http://www.diasparsoftware.com/
      > telephone: +1 416 791-8603
      > All correspondence (c) 2002 Diaspar Software Services.
      > If you want to use it, just ask; don't steal.
    • Jason Rogers
      I stand corrected, that is a possibility. ... -- Jason Rogers
      Message 2 of 9 , Dec 1, 2002
      View Source
      • 0 Attachment
        I stand corrected, that is a possibility.

        On Sat, 30 Nov 2002 11:46:00 +0100 (MET), john.link@... said:
        > This message only has an HTML part -- this is a text generated
        > representation
        >
        >
        > > However, if what you are saying is -- Why have try{}catch{} at all
        > in the
        > > tests? -- this is, of course, necessary for checked exceptions in
        > order
        > > to compile.
        > No, you can just have a throws-clause in the test method.
        > Johannes
        > --
        > +++ GMX - Mail, Messaging & more [1]http://www.gmx.net +++
        > NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!
        >
        > Yahoo! Groups Sponsor
        > ADVERTISEMENT
        >
        > To unsubscribe from this group, send an email to:
        > junit-unsubscribe@yahoogroups.com
        > Your use of Yahoo! Groups is subject to the [2]Yahoo! Terms of
        > Service.
        >
        > References
        >
        > Visible links
        > 1. http://www.gmx.net/
        > 2. http://docs.yahoo.com/info/terms/
        >
        > Hidden links:
        > 3.
        > http://rd.yahoo.com/M=237459.2675695.4055211.2225243/D=egroupweb/S=1705006905:HM/A=1267611/R=0/*http://ad.doubleclick.net/jump/N2524.Yahoo/B1071650;sz=300x250;ord=1038653164407429?

        --
        Jason Rogers
      • J. B. Rainsberger
        ... own? ... You re welcome. Some people claim that there is no real difference between failures and errors, but clearly there are differences. The primary
        Message 3 of 9 , Dec 2, 2002
        View Source
        • 0 Attachment
          --- In junit@y..., "ericheikkila" <ericheikkila@y...> wrote:
          > Oh...so that'll throw any uncaught exceptions up and fail on it's
          own?
          >
          > SWEET!
          >
          > THANKS! :)

          You're welcome.

          Some people claim that there is no "real" difference between failures
          and errors, but clearly there are differences. The primary difference
          is that a test failure tends to indicate that the code under test is
          failing the test; whereas a test error tends to indicate that the
          either the test itself or the operating environment as a whole is
          broken.

          Since an unexpected exception always means that something fundamental
          is broken, it makes sense to me to throw that exception up into the
          framework and flag it as an error.

          Check out Ward's Wiki for more on JUnit implementation patterns.
          http://c2.com/cgi/wiki?JavaUnit. Read a little. :)
        Your message has been successfully submitted and would be delivered to recipients shortly.