Re: unit testing Cayenne objects

From: Erik Hatcher (eri..hatchersolutions.com)
Date: Tue May 03 2005 - 14:31:06 EDT

  • Next message: Cris Daniluk: "Re: unit testing Cayenne objects"

    On May 3, 2005, at 11:29 AM, Cris Daniluk wrote:
    >> No question... but what if I only need one piece of data? DBUnit
    >> would be overkill :)
    >>
    >> I'm pragmatic like that. I'll jam in DBUnit soon though - it seems
    >> to be the best way to go at this point.
    >>
    >>
    >
    > I tend to agree with Mike - when it comes to true unit tests, I really
    > like to avoid the database as much as possible. Where I really involve
    > the database is in functional testing, and so big datasets are the
    > norm.

    Oh, I'd love for my tests to be done without needing anything
    external. But that simply isn't possible when dealing with objects
    that need persistence that I'm aware of. For example, how can I test
    my login() method without a database at all when my User object that
    has username/password is a Cayenne object? It would require a lot
    more mocking than having a real (though in memory HSQL) database around.

    But I'd love to be taught new tricks in this realm!

    > Pragmatically (or lazily), though, I do end up unit testing some stuff
    > on the db to avoid a sea of mock objects, etc etc. So, I suppose I
    > can't at all disagree with you that if you only need a few pieces of
    > data, dbUnit is a big waste!

    I'll need more data as my system evolves, for sure. And it is easy
    enough to dump a database to the DBUnit XML files - so I can use the
    system to get it into a known state, take a snapshot, and use that
    for unit testing.

    >> Excellent!
    >>
    >> I'm a big proponent of Test Driven Learning - writing unit tests to
    >> get a feel for how a framework or API works. Almost all the examples
    >> we wrote for Lucene in Action (get the source code at
    >> www.lucenebook.com) are JUnit tests that assert features of Lucene
    >> itself.
    >>
    >>
    >
    > I wish more projects offered the sort of tests you describe, as they
    > speak volumes more than any documentation ever could. Tapestry for
    > example... cough cough :)

    Tapestry has a huge set of unit tests, and Howard is ultra dedicated
    to increasing them. It is a complex mess though. I've told Howard a
    zillion times about my philosophy on complexity - it leaks! And the
    core of Tapestry is more complex than it needs to be, in my opinion.
    But, he's the king, and a brilliant one - and Tapestry mostly is what
    I need, and I'm intimate enough with it to tweak it when I need to.

         Erik



    This archive was generated by hypermail 2.0.0 : Tue May 03 2005 - 14:31:28 EDT