I am still having a issue getting over a small issue when it comes to TDD.

I need a method that will get a certain record set of filtered data from the data layer (linq2SQL). Please note that i am using the linq generated classes from that are generated from the DBML. Now the problem is that i want to write a test for this.

do i:

a) first insert the records in the test and then execute the method and test the results

b) use data that might be in the database. Not to keen on this logic cause it could cause things to break.

c) what ever you suggest?

1 Answer 1


Variation on (a).

Have a test db or subsection of the db that can be used for testing. When you are setting up your tests, have a routine that initializes the DB as you need it to begin testing (this can be done before each test, as appropriate). This may include deleting data, inserting data, etc. Then run your tests. In the Teardown phase, clean up after yourself. Can be repeated as much as is needed, without risk of disrupting live system (not a good idea to test using data in the database that is needed for anything else).

  • 1
    Good answer. I like to create throw-away databases using sqlite. That's not possible if you want to test things that are specific to the database implementation (like triggers, for example), but it does allow quick and harmless setup/teardown.
    – bogeymin
    Oct 25, 2010 at 10:24
  • 1
    @bogeymin - you can still set up a test DB with triggers if you want (you can create the whole db with a script during FixtureSetup)
    – Yaakov Ellis
    Oct 25, 2010 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.