Hi everyone
I want to introduce you to an open source project I've been working on.
It's called NBuilder and allows you create test instances using a fluent
interface.
http://code.google.com/p/nbuilder/
The intended use is for unit, integration / functional tests, acceptance tests
and generating test data for manual testing. It could probably be used for
things like returning data from stubbed services as well.
The properties of the class will (by default) be named sequentially. This is
useful because the data is predictable. e.g.
var products = Builder<Product>.CreateListOfSize(5).Build();
will always give you
Product
Id Title Description
=============================
1 Title1 Description1
2 Title2 Description2
3 Title3 Description3
4 Title4 Description4
5 Title5 Description5
NBuilder will assign values (using either the sequential strategy or a random or
other custom one) to all the properties it is able to, but you can override any
properties with specific values.
For example:
==========================
Builder<Product>
.CreateListOfSize(20)
.WhereAll()
.AreConstructedWith("TestProduct")
.WhereTheFirst(5)
.Have(x => x.Created = On.July.The4th.At(09, 00))
.And(x => x.LastEdited = On.August.The21st)
.AndTheNext(5)
.Have(x => x.Title = "A different title")
.AndTheNext(10)
.Have(x => x.Price = 5000m)
.Build();
==========================
(I've just added the fluent date format to it, see this blog post:
http://shouldbeableto.wordpress.com/2009/06/06/fluent-dates-added-to-nbuilder/)
You can also set persistence up (using the BuilderSetup class) which then allows
you to do this:
Builder<Category>.CreateListOfSize(100).Persist();
It's most of the OOTB interface is implemented using extensions methods, so the
whole thing is very extendible.
There are loads more features, I won't bother to list all them all here because
they're available on the project's home page on google code:
http://code.google.com/p/nbuilder/
There are two people contributing now, if anyone else would like to get involved
they'd be more than welcome.
I've just posted a new version, 2.1.7 up which has bug fixes and some new
features.
Please get in touch with any comments, problems, suggestions or feature
requests.
Gareth