49

I am use c# and for unit testing and integration testing usually I need to populate fields automatically based on attributes.

Lets say we will test if we can write and get back user data to database.

  • I create a user object populate fields write user to database
  • Read user object from database
  • Check fields if what I write is same as what I read

Is there any framework to populate user with test data automatically and check if two object are have the same values?

Sample code may like this

User user = new User();
AutoPopulator.Populate(user);
user.Save();
mihai
  • 4,592
  • 3
  • 29
  • 42
ilker Aksu
  • 619
  • 1
  • 5
  • 8

4 Answers4

92

You might find it relevant. Here is a list of few other frameworks as of today:

Well-known and respected:

Little-known:

Unfamiliar:

misanthrop
  • 771
  • 7
  • 32
Igor Toporet
  • 1,019
  • 1
  • 7
  • 6
18

Take a look at NBuilder. It lets you build test objects with random data, incrementing values, and anything you can probably think of. All through a nice fluent interface.

JJS
  • 6,431
  • 1
  • 54
  • 70
Michael Baldry
  • 792
  • 5
  • 19
3

Yes there is. I found this when watching session #3 of the Summer of NHibernate series by Stephen Bohlen.

His company, Microdesk, has developed a utility that will allow you to save the state of a database on test fixture construction, set the state of the database at the start of every test, and recover the original state of the database on test fixture deconstruction.

Download the utility here: Microdesk.Utility.UnitTest

For a tutorial on how to use it, watch the Summer of NHibernate session #3 video.

Ronnie Overby
  • 45,287
  • 73
  • 267
  • 346
-1

Fluent NHibernate has a feature which gives you everything on your wish-list, except the auto-population part:

Link: http://wiki.fluentnhibernate.org/Persistence_specification_testing

However, given C# with code contracts, it wouldn't be to hard to auto-magically create valid objects yourself using reflection.

Martin R-L
  • 4,039
  • 3
  • 28
  • 28