harriyott.com

Wednesday, June 29, 2005

CodeSmith is becoming really useful

We have a couple of dozen objects that get passed around in XML, and need to be stored in the database. We've written a base class to do the grunt work, but at some point, each item in the XML needs to be mapped to a parameter in a stored procedure. We started with all the database tables, and all the XML schemas, but nothing in between. There are various artifacts that need producing to get the process working from end to end.

Once the first XML to database process was finished, I used each of the major artifacts as the basis for a CodeSmith template. Using these templates, I was able to generate the next set in the time it took my colleague to work out why TeamTest was crashing when testing something using the Enterprise Library (i.e. a couple of hours).

The templates generate:
  1. A stored procedure to insert a row into the table
  2. A TSqlUnit test for this stored procedure
  3. A class derived from the base class that sets up the correct configuration file
  4. A unit test class that checks this class
  5. A stored procedure used by this unit test
  6. The basis of the mapper file
  7. The extra lines to put in the database installer script
The XPath must still be pasted into the mapper file, but this takes only five minutes, and can't be automated. This step actually needs some kind of analysis; the rest is just routine stuff that we don't need to spend time on.

2 Comments:

Anonymous said...

the rest is just routine stuff that we don't need to spend time on

unit testing shouldn't be routine, you should be thinking up test cases which may influence the results of a stored procedure, and verifying that error handling happens correctly - i.e. passing a NULL value in, a value out of range, an innapropriate value. I agree that creating a test automatically is a good starting point, but in my opinion it doesn't go far enough.

June 29, 2005 1:08 PM  
Simon said...

True. Without describing the whole system, the base class takes care of most of the difficult stuff, and there are extensive unit tests for that. These generated classes will be used by a further class, which again will be extensively tested.

Interestingly, we had the problem where two layers developed by two different people had test cases that checked the same thing. We decided that it was better to actually remove the tests from one of the layers.

Having said all that, I appreciate your comment, and I will go back and have another look and see if further tests are necessary. Thanks.

June 29, 2005 9:08 PM  

Post a Comment

Links to this post:

Create a Link

<< Home