Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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).

share|improve this answer
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 '10 at 10:24
@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 '10 at 10:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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