On May 3, 2005, at 9:36 AM, Cris Daniluk wrote:
>> 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() +
> "-dataset.xml");
>         if (classDataStream != null) {
>             dataSet = new FlatXmlDataSet(classDataStream);
>             DatabaseOperation.CLEAN_INSERT.execute(conn, dataSet);
>         }
>
Thanks again!   I have used DBUnit in the past, and have been also  
considering its use here.
> 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 :)
That is my setUp method (which you handle with DBUnit), so it's not  
testing Cayenne.  My unit test is this:
   public void testLogin() {
     User user = User.login("invalid", "password");
     assertNull(user);
     user = User.login("validuser", "password");
     assertEquals("validuser", user.getUsername());
   }
which is testing my User.login() method.
I definitely do not want or need to get into testing Cayenne itself,  
which is a risk we all take when testing things involving a  
framework.  My goal is to test my code, and my code only, but that  
will indirectly involve Cayenne of course.
     Erik
This archive was generated by hypermail 2.0.0 : Tue May 03 2005 - 10:04:59 EDT