Re: unit testing Cayenne objects

From: Mike Kienenberger (mkienen..laska.net)
Date: Tue May 03 2005 - 10:52:40 EDT

  • Next message: Erik Hatcher: "Re: unit testing Cayenne objects"

    Erik Hatcher <eri..hatchersolutions.com> wrote:
    > How are folks doing unit testing with Cayenne?

    In my last project, I also used DBUnit.
    I set up a FileConfiguration that points to "cayenne-testing.xml" as I test
    against various databases (Openbase/Oracle/HSQLDB. I want to keep the
    choosing of the database external to my testing code, and I also want to
    insure that I never run my tests against a non-testing database.

    I recently took advantage of DbGenerator to create the database, and then I
    load all of the constant data into my database using DBUnit xml files.

    For everything else, I programmically create the data. I originally stored
    the data in DBUnit xml files, but it quickly became a nightmare.
    It's still somewhat painful to set up test data, but I also wrote
    convenience methods that quickly generate various entities. Now that
    they're in place, it's fairly quick to generate different test data.

    In my new project, I plan to try to avoid testing against the database
    except for some integration testing. I don't know how realistic this will
    be, but that's my goal.

    > I will also need to implement a TestSetup to only have the database
    > created one time once I get more test cases in place and the set up
    > time becomes too painful.

    I have a singleton that manages my test connection which I call from my test
    cases. Among other things it has:

        public static void checkDatabaseSetup(Configuration configuration)
    throws Exception
        {
            if (false == recreatedSchema)
            {
                createSchema(configuration);
                loadConstantData(configuration);
                recreatedSchema = true;
            }
        }

    > I have also pasted one of my prototype test cases below to show you
    > what I'm doing and solicit critique.

    Yeah, I set up data as follows, and I generally create the data using DBUnit
    rather than Cayenne.

            public static DefaultDataSet createUser(Number userId) throws
    DataSetException, FileNotFoundException, IOException

            public static Number createAdditionalUser(DefaultDataSet targetUserDataSet,
    Number startingUserId) throws DataSetException, FileNotFoundException,
    IOException

        public static Number createAccountForUser(DefaultDataSet aDataSet,
    Number userId) throws DataSetException, FileNotFoundException, IOException

        public static Number createCustomAccountForUser(DefaultDataSet aDataSet,
    Number userId,
            String status, int ssn, Calendar pastDueDateCalendar, BigDecimal
    totalDue,
            boolean isDelinquent, boolean isClosing, boolean isBta,
            boolean isAutopay, boolean shouldSendPaperBill)



    This archive was generated by hypermail 2.0.0 : Tue May 03 2005 - 10:50:46 EDT