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

unit testing

Expand Messages
  • C. Keith Ray
    Thanks to whoever recommended Building Parsers in Java by Steven John Metsker -- not only is it elegant and yet very practical, but it even has examples of
    Message 1 of 7 , Aug 1, 2001
      Thanks to whoever recommended "Building Parsers in Java" by Steven John
      Metsker -- not only is it elegant and yet very practical, but it even has
      examples of unit test code using JUnit in the book!

      But strangely enough, not a single subclass of TestCase resides on the CD.
    • steve.metsker@acm.org
      ... John ... even has ... the CD. Perhaps I made the wrong call on this. I figured that I wouldn t publish my tests, just as I don t include tests in code I
      Message 2 of 7 , Aug 2, 2001
        --- In extremeprogramming@y..., "C. Keith Ray" <ckeithray@h...> wrote:
        > Thanks to whoever recommended "Building Parsers in Java" by Steven
        John
        > Metsker -- not only is it elegant and yet very practical, but it
        even has
        > examples of unit test code using JUnit in the book!
        >
        > But strangely enough, not a single subclass of TestCase resides on
        the CD.

        Perhaps I made the wrong call on this. I figured that I wouldn't
        publish my tests, just as I don't include tests in code I release to
        production. I might have been a little lazy, too, not wanting to
        comment my test code to the level of the code I tossed on the CD.
        Anyhow, I'm glad you liked the book. If for some reason you'd like to
        have the tests, let me know and I'll pass 'em along.

        - Steve Metsker (steve.metsker@...)
      • ericheikkila@yahoo.com
        Slacker...should ve ONLY included the unit tests, maybe one or two examples of a concrete class... ;) How that effects book sales might be an issue...but
        Message 3 of 7 , Aug 2, 2001
          Slacker...should've ONLY included the unit tests, maybe one or two
          examples of a concrete class... ;)

          How that effects book sales might be an issue...but frankly, I'd
          rather have the tests anyway. I've taken code from books before, and
          it's usually formatted poorly, lots of hungarian notation, etc
          etc...but, once again, that's just me ;)

          If I had the tests instead, I could create the classes that make the
          tests run...how much more useful would that be? Much, I would
          think . . . instead of just saying 'oh..hehehehe....I can just copy
          and paste this stuff' it'd be 'oh...hmmm, how can I make these tests
          run and create something that works'. Honestly, people would learn
          more that way, I think.

          -Eric


          --- In extremeprogramming@y..., steve.metsker@a... wrote:
          > --- In extremeprogramming@y..., "C. Keith Ray" <ckeithray@h...>
          wrote:
          > > Thanks to whoever recommended "Building Parsers in Java" by
          Steven
          > John
          > > Metsker -- not only is it elegant and yet very practical, but it
          > even has
          > > examples of unit test code using JUnit in the book!
          > >
          > > But strangely enough, not a single subclass of TestCase resides
          on
          > the CD.
          >
          > Perhaps I made the wrong call on this. I figured that I wouldn't
          > publish my tests, just as I don't include tests in code I release
          to
          > production. I might have been a little lazy, too, not wanting to
          > comment my test code to the level of the code I tossed on the CD.
          > Anyhow, I'm glad you liked the book. If for some reason you'd like
          to
          > have the tests, let me know and I'll pass 'em along.
          >
          > - Steve Metsker (steve.metsker@a...)
        • C. Keith Ray
          ... [...] ... I would like to see the unit tests and I would like to know if you developed the code test-first. If, for some reason, I want to modify the code
          Message 4 of 7 , Aug 2, 2001
            > --- In extremeprogramming@y..., "C. Keith Ray" <ckeithray@h...> wrote:
            >> Thanks to whoever recommended "Building Parsers in Java" by Steven
            [...]
            >
            > Perhaps I made the wrong call on this. I figured that I wouldn't
            > publish my tests, just as I don't include tests in code I release to
            > production. I might have been a little lazy, too, not wanting to
            > comment my test code to the level of the code I tossed on the CD.
            > Anyhow, I'm glad you liked the book. If for some reason you'd like to
            > have the tests, let me know and I'll pass 'em along.
            >
            > - Steve Metsker (steve.metsker@...)

            I would like to see the unit tests and I would like to know if you developed
            the code test-first.

            If, for some reason, I want to modify the code for my own purposes, the unit
            tests would be REALLY helpful.

            You could upload them to this mailing list's file archive, or otherwise put
            them on the web, they would be a valuable example of unit testing... and
            everybody could use more examples. If you're not interested in that, could
            you please email them to me?

            ----

            C. Keith Ray
            <http://homepage.mac.com/keithray/resume.html>
          • Ron Jeffries
            ... Recall that one of the reasons code doesn t need paper documents is the tests. If you got em, including them would be the Extreme thing to do. Now about
            Message 5 of 7 , Aug 2, 2001
              Responding to steve.metsker@... (12:22 PM 8/2/2001 +0000):
              >Perhaps I made the wrong call on this. I figured that I wouldn't
              >publish my tests, just as I don't include tests in code I release to
              >production. I might have been a little lazy, too, not wanting to
              >comment my test code to the level of the code I tossed on the CD.
              >Anyhow, I'm glad you liked the book. If for some reason you'd like to
              >have the tests, let me know and I'll pass 'em along.

              Recall that one of the reasons code doesn't need paper documents is the
              tests. If you got 'em, including them would be the Extreme thing to do.

              Now about those comments ...

              Ron Jeffries
              www.XProgramming.com
              The practices are not the knowing. They are a path to the knowing.
            • steve_metsker@yahoo.com
              ... developed ... I uploaded my tests as bpwj_testing.jar. It s kinda embarrassing that there aren t really too many tests here, maybe a hundred. If I d known
              Message 6 of 7 , Aug 3, 2001
                >
                > I would like to see the unit tests and I would like to know if you
                developed
                > the code test-first.

                I uploaded my tests as bpwj_testing.jar.

                It's kinda embarrassing that there aren't really too many tests here,
                maybe a hundred. If I'd known this would come up in this audience I
                mighta written a few more.

                I must admit, too, that I do not usually follow the practice of
                test-first programming. I don't have a good excuse here, but if I
                think of one I'll post it.
                >

                Steve Metsker
              • steve_metsker@yahoo.com
                ... Let s see. Here s a test class that imports temporal.*; The challenge is to write this package so that the tests run. The tests verify (to some degree)
                Message 7 of 7 , Aug 3, 2001
                  --- In extremeprogramming@y..., ericheikkila@y... wrote:
                  >
                  >
                  > If I had the tests instead, I could create the classes that make the
                  > tests run...how much more useful would that be?

                  Let's see. Here's a test class that imports temporal.*;

                  The challenge is to write this package so that the tests run. The
                  tests verify (to some degree) that you can adequately model temporal
                  relations, specifically marriage.

                  I would be interested in hearing how much time and how much code it
                  takes to meet this challenge. Is this a good way to provide challenges
                  (or homework)?

                  - Steve Metsker
                  ----------------------------------------<snip>------------------
                  package testing;

                  import java.util.*;
                  import java.text.*;
                  import junit.framework.*;
                  import temporal.*;

                  import marriage.*;

                  /**
                  * Test <code>marriage</code>.
                  *
                  */
                  public class MarriageTest extends TestCase {
                  protected static DateFormat dateFormat;

                  public MarriageTest(String name) {
                  super(name);
                  }

                  public static iDate date(String s)
                  throws ParseException {

                  return new MyDate(dateFormat().parse(s).getTime());
                  }

                  public static DateFormat dateFormat() {
                  if (dateFormat == null) {
                  dateFormat = new SimpleDateFormat("MMM dd yyyy");
                  }
                  return dateFormat;
                  }
                  public void testBigamy()
                  throws ParseException, MarriageException {
                  Person jim = new Person("jim");
                  Person julie = new Person("julie");
                  Person jane = new Person("jane");

                  iDate wedding1 = date("Aug 14 1950");
                  iDate wedding2 = date("Mar 3 1971");

                  jim.marry(wedding1, julie);
                  try {
                  jim.marry(wedding2, jane);
                  }
                  catch (MarriageException e) { // right!
                  return;
                  }
                  fail("Jim is allowed to marry twice simultaneously");

                  }
                  public void testMarriage()
                  throws ParseException, MarriageException {
                  Person jim = new Person("jim");
                  Person julie = new Person("julie");
                  iDate before = date("Aug 14 1950");
                  iDate on = date("Aug 15 1950");
                  iDate after = date("Aug 16 1950");
                  jim.marry(on, julie);
                  assert(!julie.isSingle(after));
                  }
                  public void testSerial()
                  throws ParseException, MarriageException {
                  Person jim = new Person("jim");
                  Person julie = new Person("julie");
                  Person jane = new Person("jane");
                  iDate beforeWedding1 = date("Aug 13 1950");
                  iDate wedding1 = date("Aug 14 1950");
                  iDate afterWedding1 = date("Aug 15 1950");
                  iDate divorce = date("Dec 7 1965");
                  iDate afterDivorce = date("Dec 8 1965");
                  iDate wedding2 = date("Mar 3 1971");
                  iDate afterWedding2 = date("Mar 4 1971");
                  jim.marry(wedding1, julie);
                  julie.divorce(divorce);
                  jane.marry(wedding2, jim);
                  assert(!jim.isSingle(afterWedding1));
                  assert(!julie.isSingle(afterWedding1));
                  assert(jane.isSingle(afterWedding1));
                  assert(jim.isSingle(afterDivorce));
                  assert(julie.isSingle(afterDivorce));
                  assert(jane.isSingle(afterDivorce));
                  assert(!jim.isSingle(afterWedding2));
                  assert(julie.isSingle(afterWedding2));
                  assert(!jane.isSingle(afterWedding2));
                  }
                  public void testSingle() {
                  Person jim = new Person("jim");
                  assert(jim.isSingle(new MyDate()));
                  }
                  }
                Your message has been successfully submitted and would be delivered to recipients shortly.