Re: unit testing Cayenne objects

From: Cris Daniluk (
Date: Tue May 03 2005 - 09:36:19 EDT

  • Next message: Cris Daniluk: "Re: DataContextPool"

    > 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.

    Unfortunately, I don't have the time to give this the same level of detail :)

    But, what you are suggesting is perfectly fine. Because HSQL can't
    quite suit all of our testing needs, we have an Oracle schema
    dedicated to the unit tests. The setUp() invokes a truncate_tables
    procedure which ensures the schema is clean, then proceeds to load
    global data using dbUnit. Then, an optional class-specific dataset is
    loaded so that the TestCase has everything it needs to boostrap
    itself. Something like this:

    InputStream classDataStream =
    getClass().getResourceAsStream(getClass().getSimpleName() +
            if (classDataStream != null) {
                dataSet = new FlatXmlDataSet(classDataStream);
                DatabaseOperation.CLEAN_INSERT.execute(conn, dataSet);

    So, rather than this:

    > User user = (User) getDataContext().createAndRegisterNewObject
    > (User.class);
    > user.setUsername("validuser");
    > user.setPassword("password");
    > getDataContext().commitChanges();

    I would instead add it to UserTest-dataset.xml and let dbUnit load it
    (after all, all this code serves to do is test Cayenne, which has its
    own unit tests!). This is more a matter of style and complexity of the
    model, so as usual, I'm just providing food for thought :)


    This archive was generated by hypermail 2.0.0 : Tue May 03 2005 - 09:36:21 EDT