CodGen Tips

Posts   
 
    
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 24-May-2004 14:42:15   

I am planning on writing a small app that will codegen unit test classes for use with NUnit. I read this book on "Code Generation in Microsoft .NET." It was a pretty good primer with regards to codegen.

Unfortunately, the author did not really go into best practices for extraction of meta data using reflection.

Does anyone have any tips or know of any other reading that could help with the reflectional meta data extraction?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39826
Joined: 17-Aug-2003
# Posted on: 25-May-2004 10:07:36   

Isn't the point of unit-testing that you test semantics of an interface? I.e.: the syntax of an interface is defined in the interface (or class interface) itself. The semantics are defined in the documentation, description of the interface (as C#/VB.NET don't have pre-/post conditions like Eiffel). So IMHO, you need to hand-write unit-tests to make them actually useful.

Or are you looking for a generator which sets up the initial framework for the unit tests, and you fill in the actual test conditions yourself?

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 26-May-2004 08:57:42   

Well, with a service based interface, you typically have methods like:

UpdateInvoice(customer as CustomerEntity, invoice as InvoiceEntity, details as EntityCollection) or LateCustomers(daysPastDue as int) as entityCollection.

All I am trying to do is jump start the wireframe coding for making calls to UpdateInvoice and LateCustomer. Yes, testers need to be aware, that valid objects need to be passed, and they need to be somewhat familiar with the data.

So, I have been playing around with this code gen harness tool. Basically, I am at the point where I need to write a quick tool that extracts metadata from the services layer and put it into an xml file that can be parsed by some XSLT templates that I define.

So to answer

Or are you looking for a generator which sets up the initial framework for the unit tests, and you fill in the actual test conditions yourself?

Yes, I want to code gen the basic test cases, and do some of the initial work, like providing constructors for objects, setting initial values, initializing dataAccessAdapters.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39826
Joined: 17-Aug-2003
# Posted on: 26-May-2004 10:08:21   

I think with some reflection methods (they're rather easy, grabbing properties and methods) it is rather simple to produce meta data which can be used to generate code. What did you construct already or are you puzzled where to start?

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 26-May-2004 10:50:52   

I am kind of puzzled as to where to start and I am kind of looking for some reassurance that I havnet lost my mind simple_smile

I have the code gen harness that allows me to plug in various scripts, i.e. XSLTTransforms, BruteForce code gen, or CodeDOM codegen.

So I am thinking that my next steps would be to, define an routine to build the metadata using reflection, then define some XSLT transforms/templates to work with the schema. Then extract the meta and transform it. Add the files to an NUnit test project and go.

Are there any steps or pitfalls that I should know about?