Generating test data?

Posts   
 
    
tangent
User
Posts: 41
Joined: 30-Apr-2006
# Posted on: 21-May-2008 10:57:43   

I would like to be able to use LLBL to generate test dummy classes populated with data from my DB. I think this would be very convenient for writing unit tests.

I know that I can do this with codesmith, but I would prefer to do it with LLBL since all of the mapping data is already there.

Is there any way to do this via a plugin or custom task?

Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005
# Posted on: 21-May-2008 15:13:33   

I'm not sure I grasp the idea.

On what basis would these classes be populated? Do you mean you want them to be populated with data at runtime?

To fetch entities you need PK values? These won't be available at design time, would they?

I think Test code should be manually created, based on pre-known values.

tangent
User
Posts: 41
Joined: 30-Apr-2006
# Posted on: 21-May-2008 19:33:57   

I mean like you retrieve the first 20 rows from the DB during code generation and then either serialize that data or just insert the raw data into a stub class which can then be used from unit tests without touching the DB.

ie if you have an OrderEntity then you could have a class called OrderEntityTestStub which has a method like OrderEntityTestStub.GetTestCollection() that retrieves a pre-populated collection of entities. (at run time, not design time)

Mainly the only thing I need to know how to do is how to access the DB during the code generation process, or if that is possible at all.

Walaa avatar
Walaa
Support Team
Posts: 14987
Joined: 21-Aug-2005
# Posted on: 22-May-2008 09:59:57   

Is there any way to do this via a plugin or custom task?

Then, all you need to do is create a template to be used at generation time to generate unit-test code.

You should check the SDK manual, as a start.

tangent
User
Posts: 41
Joined: 30-Apr-2006
# Posted on: 26-May-2008 09:08:57   

I already have a template to generate unit test stubs, what I want is to pull data from the DB during the generation (or schema refresh) process, not schema information but the actual content of the rows.

I would then serialize the data and have my unit tests load it at runtime to have automatically populated test data so my tests can run with no access to DB.

The only thing I don't know how to do is how to have the LLBL engine pull data from the DB rather than schema information during the generation/refresh process. Is this possible?

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 26-May-2008 19:59:48   

Template code is executed against .net/c# compiler, so all you need to do is add the corresponding using statement(s) (System.Data) and then create a connection string to your database and access it with Ado.Net.